Submission #837439

#TimeUsernameProblemLanguageResultExecution timeMemory
837439_martynasRope (JOI17_rope)C++11
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 1e6+5; int n, m; int a[mxn]; int main(int argc, char const *argv[]) { cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 1; i <= m; i++) { // skip first int best = n, curr = 0, mx, j; map<int, int> cnt; for(j = 1; j < n-1; j += 2) { if(a[j] != i && a[j+1] != i) { cnt[a[j]]++, cnt[a[j+1]]++; curr += 2; } else if(a[j] != i || a[j+1] != i) { curr++; } } if(j == n-1) if(a[n-1] != i) curr++, cnt[a[n-1]]++; mx = 0; for(auto p : cnt) mx = max(mx, p.second); curr -= mx; best = min(best, curr); // pair first curr = 0; cnt.clear(); for(j = 0; j < n-1; j += 2) { if(a[j] != i && a[j+1] != i) { cnt[a[j]]++, cnt[a[j+1]]++; curr += 2; } else if(a[j] != i || a[j+1] != i) { curr++; } } if(j == n-1) if(a[n-1] != i) curr++, cnt[a[n-1]]++; mx = 0; for(auto p : cnt) mx = max(mx, p.second); curr -= mx; best = min(best, curr); cout << best << "\n"; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...