Submission #36244

#TimeUsernameProblemLanguageResultExecution timeMemory
36244touristk2000Money (IZhO17_money)C++14
100 / 100
556 ms17648 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e6 + 1; int main(){ int n; scanf("%d", &n); vector<int> a(n); vector<int> cnt(MAXN); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); cnt[a[i]]++; } vector<int> pr(MAXN + 1), nxt(MAXN + 1, MAXN); { int lst = 0; for (int i = 1; i <= MAXN; ++i) { pr[i] = lst; if (cnt[i]) nxt[lst] = i, lst = i; } } int ans = 0; for (int i = n - 1; i >= 0;) { ++ans; int j = i; while (i > 0) { int p = pr[a[i]]; if (a[i - 1] == a[i]) { if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } else { if (p == a[i - 1] && (cnt[a[i]] == 1 || a[j] == a[i])) { if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } else { break; } } } if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
money.cpp:12:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...