제출 #837443

#제출 시각아이디문제언어결과실행 시간메모리
837443_martynasRope (JOI17_rope)C++11
45 / 100
2581 ms1104 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; if(a[0] != i) curr++, cnt[a[0]]++; 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...