Submission #81142

#TimeUsernameProblemLanguageResultExecution timeMemory
81142FutymyCloneBaloni (COCI15_baloni)C++14
0 / 100
128 ms8532 KiB
#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)

baloni.cpp: In function 'int main()':
baloni.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n); dsu.init(n);
     ~~~~~^~~~~~~~~~
baloni.cpp:29:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...