# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81142 | FutymyClone | Baloni (COCI15_baloni) | C++14 | 128 ms | 8532 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 N = 1e6 + 5;
struct disj {
int par[N];
void init (int n) {
for (int i = 1; i <= n; i++) par[i] = i;
}
int Find (int x) {
return par[x] == x ? x : par[x] = Find(par[x]);
}
void join (int x, int y) {
x = Find(x); y = Find(y);
if (x == y) return;
par[y] = x;
}
} dsu;
int n, a[N], last[N];
bool used[N];
int main(){
scanf("%d", &n); dsu.init(n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (last[a[i] + 1] && !used[last[a[i] + 1]]) dsu.join(i, last[a[i] + 1]), used[last[a[i] + 1]] = true;
last[a[i]] = i;
}
int ans = 0;
for (int i = 1; i <= n; i++) ans += dsu.par[i] == i;
printf("%d", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |