diff --git a/ABC451/dib3474/A.cpp b/ABC451/dib3474/A.cpp new file mode 100644 index 0000000..b14062e --- /dev/null +++ b/ABC451/dib3474/A.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main() { + string s; + cin >> s; + if (s.size() % 5 == 0) { + cout << "Yes" << '\n'; + } + else { + cout << "No" << '\n'; + } +} \ No newline at end of file diff --git a/ABC451/dib3474/B.cpp b/ABC451/dib3474/B.cpp new file mode 100644 index 0000000..ceebcef --- /dev/null +++ b/ABC451/dib3474/B.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +vector 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'; + } +} \ No newline at end of file diff --git a/ABC451/dib3474/C.cpp b/ABC451/dib3474/C.cpp new file mode 100644 index 0000000..47fac8b --- /dev/null +++ b/ABC451/dib3474/C.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +priority_queue, greater> 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'; + } + } +} \ No newline at end of file diff --git a/ABC451/dib3474/E.cpp b/ABC451/dib3474/E.cpp new file mode 100644 index 0000000..3fdcf28 --- /dev/null +++ b/ABC451/dib3474/E.cpp @@ -0,0 +1,87 @@ +#include +using namespace std; + +vector>> graph; +vector> board; +vector> 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, Compare> pq; + +vector 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(n + 1)); + parent.assign(n + 1, 0); + for(int i=1; i<=n; i++) parent[i] = i; + graph.assign(n + 1, vector>()); + costs.assign(n + 1, vector(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"; +} \ No newline at end of file