# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
636124 | 2022-08-28T08:39:56 Z | aris12345678 | Baloni (COCI15_baloni) | C++14 | 123 ms | 34396 KB |
#include <bits/stdc++.h> using namespace std; const int mxN = 1e6+5; int par[mxN], sz[mxN]; vector<int> pos[mxN]; void make_set(int x) { par[x] = x, sz[x] = 1; } int find_set(int x) { return par[x] == x ? x : par[x] = find_set(par[x]); } bool union_sets(int x, int y) { x = find_set(x), y = find_set(y); if(x == y) return false; if(sz[x] < sz[y]) swap(x, y); par[y] = x, sz[x] += sz[y]; return true; } int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) make_set(i); int ans = n; for(int i = 0; i < n; i++) { int x; scanf("%d", &x); pos[x].push_back(i); if(!pos[x+1].empty()) { if(union_sets(i, pos[x+1].back())) ans--; pos[x+1].pop_back(); } } printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23792 KB | Output is correct |
2 | Correct | 13 ms | 23836 KB | Output is correct |
3 | Correct | 11 ms | 23772 KB | Output is correct |
4 | Correct | 13 ms | 23892 KB | Output is correct |
5 | Correct | 113 ms | 33620 KB | Output is correct |
6 | Correct | 114 ms | 34396 KB | Output is correct |
7 | Correct | 93 ms | 32392 KB | Output is correct |
8 | Correct | 106 ms | 32332 KB | Output is correct |
9 | Correct | 123 ms | 33028 KB | Output is correct |
10 | Correct | 111 ms | 33248 KB | Output is correct |