# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
256292 |
2020-08-02T13:50:33 Z |
pit4h |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
89540 KB |
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
vector<int> a(n), occ(m+1);
vector<vector<pair<int, int>>> col(m+1);
vector<pair<int, int>> best;
for(int i=0; i<n; ++i) {
cin>>a[i];
occ[a[i]]++;
if(i==0 || a[i] != a[i-1]) {
col[a[i]].push_back({i, i});
}
else {
col[a[i]].back().nd = i;
}
}
for(int i=1; i<=m; ++i) {
best.push_back({occ[i], i});
}
sort(best.rbegin(), best.rend());
for(int c=1; c<=m; ++c) {
if(col[c].empty()) continue;
vector<vector<int>> cnt(2, vector<int>(m+1));
vector<int> prv(2);
vector<bool> fail(2);
int beg = col[c][0].st;
int end = col[c][0].nd;
if(end==n-1) {
int ans = n;
for(int i=1; i<=m; ++i) {
if(c==i) {
ans = min(ans, n-occ[c]);
}
else {
ans = min(ans, n - occ[c] - occ[i]);
}
}
cout<<ans<<'\n';
continue;
}
if((end-beg+1)%2==1) {
if(beg==0) {
prv[0] = end;
cnt[1][a[end+1]] = 1;
prv[1] = end+1;
}
else {
cnt[0][a[beg-1]] = 1;
prv[0] = end;
cnt[1][a[end+1]] = 1;
prv[1] = end+1;
}
}
else {
if(beg==0) {
prv[0] = end;
cnt[1][a[end+1]] = 1;
prv[1] = end+1;
}
else {
prv[0] = end;
cnt[1][a[beg-1]] = 1;
cnt[1][a[end+1]] = 1;
prv[1] = end+1;
}
}
for(int it=0; it<=1; ++it) {
bool start=0;
for(auto cur: col[c]) {
if(!start) {
start=1;
continue;
}
beg = cur.st;
end = cur.nd;
if((beg-prv[it])%2==0) {
beg--;
cnt[it][a[beg]]++;
}
if((end-beg+1)%2==1 && end != n-1) {
end++;
cnt[it][a[end]]++;
}
prv[it] = end;
}
}
int ans = n;
for(int i=1; i<=m; ++i) {
if(c==i) {
ans = min(ans, n-occ[c]);
}
else {
if(!fail[0]) ans = min(ans, n - occ[c] - occ[i] + cnt[0][i]);
if(!fail[1]) ans = min(ans, n - occ[c] - occ[i] + cnt[1][i]);
}
}
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
2048 KB |
Output is correct |
28 |
Correct |
10 ms |
1784 KB |
Output is correct |
29 |
Correct |
10 ms |
2048 KB |
Output is correct |
30 |
Correct |
13 ms |
1648 KB |
Output is correct |
31 |
Correct |
11 ms |
2176 KB |
Output is correct |
32 |
Correct |
9 ms |
1664 KB |
Output is correct |
33 |
Correct |
11 ms |
1920 KB |
Output is correct |
34 |
Correct |
9 ms |
1760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
2048 KB |
Output is correct |
28 |
Correct |
10 ms |
1784 KB |
Output is correct |
29 |
Correct |
10 ms |
2048 KB |
Output is correct |
30 |
Correct |
13 ms |
1648 KB |
Output is correct |
31 |
Correct |
11 ms |
2176 KB |
Output is correct |
32 |
Correct |
9 ms |
1664 KB |
Output is correct |
33 |
Correct |
11 ms |
1920 KB |
Output is correct |
34 |
Correct |
9 ms |
1760 KB |
Output is correct |
35 |
Correct |
20 ms |
2180 KB |
Output is correct |
36 |
Correct |
14 ms |
2176 KB |
Output is correct |
37 |
Correct |
14 ms |
2176 KB |
Output is correct |
38 |
Correct |
13 ms |
2176 KB |
Output is correct |
39 |
Correct |
15 ms |
2176 KB |
Output is correct |
40 |
Correct |
12 ms |
2432 KB |
Output is correct |
41 |
Correct |
12 ms |
2432 KB |
Output is correct |
42 |
Correct |
13 ms |
2304 KB |
Output is correct |
43 |
Correct |
13 ms |
2432 KB |
Output is correct |
44 |
Correct |
13 ms |
2432 KB |
Output is correct |
45 |
Correct |
13 ms |
2432 KB |
Output is correct |
46 |
Correct |
12 ms |
2304 KB |
Output is correct |
47 |
Correct |
15 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
2048 KB |
Output is correct |
28 |
Correct |
10 ms |
1784 KB |
Output is correct |
29 |
Correct |
10 ms |
2048 KB |
Output is correct |
30 |
Correct |
13 ms |
1648 KB |
Output is correct |
31 |
Correct |
11 ms |
2176 KB |
Output is correct |
32 |
Correct |
9 ms |
1664 KB |
Output is correct |
33 |
Correct |
11 ms |
1920 KB |
Output is correct |
34 |
Correct |
9 ms |
1760 KB |
Output is correct |
35 |
Correct |
20 ms |
2180 KB |
Output is correct |
36 |
Correct |
14 ms |
2176 KB |
Output is correct |
37 |
Correct |
14 ms |
2176 KB |
Output is correct |
38 |
Correct |
13 ms |
2176 KB |
Output is correct |
39 |
Correct |
15 ms |
2176 KB |
Output is correct |
40 |
Correct |
12 ms |
2432 KB |
Output is correct |
41 |
Correct |
12 ms |
2432 KB |
Output is correct |
42 |
Correct |
13 ms |
2304 KB |
Output is correct |
43 |
Correct |
13 ms |
2432 KB |
Output is correct |
44 |
Correct |
13 ms |
2432 KB |
Output is correct |
45 |
Correct |
13 ms |
2432 KB |
Output is correct |
46 |
Correct |
12 ms |
2304 KB |
Output is correct |
47 |
Correct |
15 ms |
2432 KB |
Output is correct |
48 |
Correct |
199 ms |
22136 KB |
Output is correct |
49 |
Correct |
211 ms |
22184 KB |
Output is correct |
50 |
Correct |
228 ms |
22136 KB |
Output is correct |
51 |
Correct |
211 ms |
21624 KB |
Output is correct |
52 |
Correct |
148 ms |
18552 KB |
Output is correct |
53 |
Correct |
159 ms |
20600 KB |
Output is correct |
54 |
Correct |
167 ms |
18552 KB |
Output is correct |
55 |
Correct |
174 ms |
18168 KB |
Output is correct |
56 |
Correct |
167 ms |
17528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
10 ms |
2048 KB |
Output is correct |
28 |
Correct |
10 ms |
1784 KB |
Output is correct |
29 |
Correct |
10 ms |
2048 KB |
Output is correct |
30 |
Correct |
13 ms |
1648 KB |
Output is correct |
31 |
Correct |
11 ms |
2176 KB |
Output is correct |
32 |
Correct |
9 ms |
1664 KB |
Output is correct |
33 |
Correct |
11 ms |
1920 KB |
Output is correct |
34 |
Correct |
9 ms |
1760 KB |
Output is correct |
35 |
Correct |
20 ms |
2180 KB |
Output is correct |
36 |
Correct |
14 ms |
2176 KB |
Output is correct |
37 |
Correct |
14 ms |
2176 KB |
Output is correct |
38 |
Correct |
13 ms |
2176 KB |
Output is correct |
39 |
Correct |
15 ms |
2176 KB |
Output is correct |
40 |
Correct |
12 ms |
2432 KB |
Output is correct |
41 |
Correct |
12 ms |
2432 KB |
Output is correct |
42 |
Correct |
13 ms |
2304 KB |
Output is correct |
43 |
Correct |
13 ms |
2432 KB |
Output is correct |
44 |
Correct |
13 ms |
2432 KB |
Output is correct |
45 |
Correct |
13 ms |
2432 KB |
Output is correct |
46 |
Correct |
12 ms |
2304 KB |
Output is correct |
47 |
Correct |
15 ms |
2432 KB |
Output is correct |
48 |
Correct |
199 ms |
22136 KB |
Output is correct |
49 |
Correct |
211 ms |
22184 KB |
Output is correct |
50 |
Correct |
228 ms |
22136 KB |
Output is correct |
51 |
Correct |
211 ms |
21624 KB |
Output is correct |
52 |
Correct |
148 ms |
18552 KB |
Output is correct |
53 |
Correct |
159 ms |
20600 KB |
Output is correct |
54 |
Correct |
167 ms |
18552 KB |
Output is correct |
55 |
Correct |
174 ms |
18168 KB |
Output is correct |
56 |
Correct |
167 ms |
17528 KB |
Output is correct |
57 |
Execution timed out |
2594 ms |
89540 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |