Submission #528660

#TimeUsernameProblemLanguageResultExecution timeMemory
528660ApiramIzbori (COCI22_izbori)C++14
15 / 110
14 ms5812 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = (int)3e5 +5; signed main() { cin.tie(nullptr)->ios_base::sync_with_stdio(false); int n; cin>>n; vector<int>v(n); bool ok = 0; for(auto &z : v) { cin>>z; if(z == 3) ok = 1; z = z == 1 ? -1 : 1; } if(ok) { cout << 10; return 0; } int curr = mxN; vector<int>p(4*mxN,0); int64_t ans = 0, d = 0; for(int i = 0 ; i < n ; i++) { if(v[i] == 1) { p[++curr]++; d += p[curr]; } else { p[curr+1]++; d -= p[curr--]; } ans += d; } p.clear(); p.resize(4*mxN,0); curr = mxN; int64_t ans2 = 0; d = 0; for(int i = 0 ; i < n ; i++) { if(v[i] == -1) { p[++curr]++; d += p[curr]; } else { p[curr+1]++; d -= p[curr--]; } ans2 += d; } cout << ans + ans2; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...