Submission #103616

#TimeUsernameProblemLanguageResultExecution timeMemory
103616leonardaBaloni (COCI15_baloni)C++14
100 / 100
1550 ms92480 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef pair<int, int> pi; typedef long long int lint; const int inf = 0x3f3f3f3f; const int maxn = 1e6 + 5; int n, ans; set<int> v[maxn]; int a[maxn]; bool memo[maxn]; int main () { ios::sync_with_stdio(0); cin >> n; for(int i = 0; i < n; ++i) { cin >> a[i]; v[a[i]].insert(i); } for(int i = 0; i < n; ++i) { if(v[a[i]].count(i) == 0) continue; int indeks = i; while(indeks != -1) { v[a[indeks]].erase(indeks); set<int>::iterator it = v[a[indeks] - 1].lower_bound(indeks); if(it == v[a[indeks] - 1].end()) indeks = -1; else indeks = *it; } ++ans; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...