# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636124 | aris12345678 | Baloni (COCI15_baloni) | C++14 | 123 ms | 34396 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |