# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
837439 |
2023-08-25T10:52:33 Z |
_martynas |
Rope (JOI17_rope) |
C++11 |
|
1 ms |
212 KB |
#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 time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |