Submission #636124

#TimeUsernameProblemLanguageResultExecution timeMemory
636124aris12345678Baloni (COCI15_baloni)C++14
100 / 100
123 ms34396 KiB
#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)

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]
   28 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
baloni.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...