Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ABC451/dib3474/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
string s;
cin >> s;
if (s.size() % 5 == 0) {
cout << "Yes" << '\n';
}
else {
cout << "No" << '\n';
}
}
24 changes: 24 additions & 0 deletions ABC451/dib3474/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
using namespace std;

vector<int> before, after;

int main() {
int n, m;
cin >> n >> m;

before.assign(m + 1, 0);
after.assign(m + 1, 0);

for (int i = 0; i < n; i++) {
int b, a;
cin >> b >> a;

before[b]++;
after[a]++;
}

for (int i = 1; i <= m; i++) {
cout << after[i] - before[i] << '\n';
}
}
25 changes: 25 additions & 0 deletions ABC451/dib3474/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;

priority_queue<int, vector<int>, greater<int>> trees;

int main() {
cin.tie(0)->sync_with_stdio(0);

int Q;
cin >> Q;
while (Q--) {
int q, h;
cin >> q >> h;
if (q == 1) {
trees.push(h);
cout << trees.size() << '\n';
}
else if (q == 2) {
while (!trees.empty() && trees.top() <= h) {
trees.pop();
}
cout << trees.size() << '\n';
}
}
}
87 changes: 87 additions & 0 deletions ABC451/dib3474/E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int, int>>> graph;
vector<vector<int>> board;
vector<vector<int>> costs;

struct node {
int a;
int b;
int w;
};

struct Compare {
bool operator()(const node& i, const node& j) {
return i.w > j.w;
}
};

priority_queue<node, vector<node>, Compare> pq;

vector<int> parent;

int find(int e) {
if (parent[e] == e) return e;
else {
return parent[e] = find(parent[e]);
}
}

int n;

void dfs(int start, int curr, int prev, int total_dist) {
costs[start][curr] = total_dist;
for (auto& [next_node, weight] : graph[curr]) {
if (next_node != prev) {
dfs(start, next_node, curr, total_dist + weight);
}
}
}

int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
board.assign(n + 1, vector<int>(n + 1));
parent.assign(n + 1, 0);
for(int i=1; i<=n; i++) parent[i] = i;
graph.assign(n + 1, vector<pair<int, int>>());
costs.assign(n + 1, vector<int>(n + 1, 0));

for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
cin >> board[i][j];
pq.push({i, j, board[i][j]});
}
}

int edges = 0;
while(!pq.empty() && edges < n - 1) {
auto [a, b, w] = pq.top(); pq.pop();
if (find(a) != find(b)) {
parent[find(a)] = find(b);
graph[a].push_back({b, w});
graph[b].push_back({a, w});
edges++;
}
}

if (edges != n -1) {
cout << "No";
return 0;
}

for (int i = 1; i <= n; i++) {
dfs(i, i, -1, 0);
}

for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (costs[i][j] != board[i][j]) {
cout << "No";
return 0;
}
}
}
cout << "Yes";
}