# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539185 |
2022-03-18T14:37:09 Z |
vector |
Rope (JOI17_rope) |
C++17 |
|
1384 ms |
134064 KB |
#include<bits/stdc++.h>
#define SIZE 1000001
using namespace std;
int N,M,A[SIZE],B[SIZE],C[SIZE],D[SIZE],ans[SIZE],mx;
bool vis[SIZE];
vector<int>v1[SIZE],v2[SIZE];
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>A[i];
B[A[i]]++;
}
for(int i=1;i<=M;i++){
C[B[i]]++;
mx=max(mx,B[i]);
ans[i]=1e9;
}
for(int i=1;i<N;i+=2){
v1[A[i]].push_back(A[i+1]);
v1[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
int mx1=mx;
vector<int>u;
u.push_back(i);
for(int j:v1[i]){
u.push_back(j);
D[j]++;
}
D[i]=B[i];
for(int j:u)if(!vis[j]){
C[B[j]-D[j]]++;
C[B[j]]--;
vis[j]=true;
}
while(!C[mx1])mx1--;
for(int j:u){
C[B[j]-D[j]]--;
D[j]=0,vis[j]=false;
C[B[j]]++;
}
ans[i]=min(ans[i],N-B[i]-mx1);
}
for(int i=2;i<N;i+=2){
v2[A[i]].push_back(A[i+1]);
v2[A[i+1]].push_back(A[i]);
}
for(int i=1;i<=M;i++){
int mx1=mx;
vector<int>u;
u.push_back(i);
for(int j:v2[i]){
u.push_back(j);
D[j]++;
}
D[i]=B[i];
for(int j:u)if(!vis[j]){
C[B[j]-D[j]]++;
C[B[j]]--;
vis[j]=true;
}
while(!C[mx1])mx1--;
for(int j:u){
C[B[j]-D[j]]--;
D[j]=0,vis[j]=false;
C[B[j]]++;
}
ans[i]=min(ans[i],N-B[i]-mx1);
printf("%d\n",ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47288 KB |
Output is correct |
2 |
Correct |
27 ms |
47256 KB |
Output is correct |
3 |
Correct |
29 ms |
47288 KB |
Output is correct |
4 |
Correct |
28 ms |
47316 KB |
Output is correct |
5 |
Correct |
27 ms |
47288 KB |
Output is correct |
6 |
Correct |
27 ms |
47272 KB |
Output is correct |
7 |
Correct |
26 ms |
47220 KB |
Output is correct |
8 |
Correct |
32 ms |
47216 KB |
Output is correct |
9 |
Correct |
26 ms |
47308 KB |
Output is correct |
10 |
Correct |
26 ms |
47232 KB |
Output is correct |
11 |
Correct |
27 ms |
47324 KB |
Output is correct |
12 |
Correct |
28 ms |
47284 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
28 ms |
47240 KB |
Output is correct |
15 |
Correct |
28 ms |
47264 KB |
Output is correct |
16 |
Correct |
26 ms |
47308 KB |
Output is correct |
17 |
Correct |
27 ms |
47252 KB |
Output is correct |
18 |
Correct |
29 ms |
47236 KB |
Output is correct |
19 |
Correct |
26 ms |
47284 KB |
Output is correct |
20 |
Correct |
27 ms |
47312 KB |
Output is correct |
21 |
Correct |
26 ms |
47316 KB |
Output is correct |
22 |
Correct |
27 ms |
47312 KB |
Output is correct |
23 |
Correct |
28 ms |
47216 KB |
Output is correct |
24 |
Correct |
26 ms |
47316 KB |
Output is correct |
25 |
Correct |
26 ms |
47316 KB |
Output is correct |
26 |
Correct |
31 ms |
47316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47288 KB |
Output is correct |
2 |
Correct |
27 ms |
47256 KB |
Output is correct |
3 |
Correct |
29 ms |
47288 KB |
Output is correct |
4 |
Correct |
28 ms |
47316 KB |
Output is correct |
5 |
Correct |
27 ms |
47288 KB |
Output is correct |
6 |
Correct |
27 ms |
47272 KB |
Output is correct |
7 |
Correct |
26 ms |
47220 KB |
Output is correct |
8 |
Correct |
32 ms |
47216 KB |
Output is correct |
9 |
Correct |
26 ms |
47308 KB |
Output is correct |
10 |
Correct |
26 ms |
47232 KB |
Output is correct |
11 |
Correct |
27 ms |
47324 KB |
Output is correct |
12 |
Correct |
28 ms |
47284 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
28 ms |
47240 KB |
Output is correct |
15 |
Correct |
28 ms |
47264 KB |
Output is correct |
16 |
Correct |
26 ms |
47308 KB |
Output is correct |
17 |
Correct |
27 ms |
47252 KB |
Output is correct |
18 |
Correct |
29 ms |
47236 KB |
Output is correct |
19 |
Correct |
26 ms |
47284 KB |
Output is correct |
20 |
Correct |
27 ms |
47312 KB |
Output is correct |
21 |
Correct |
26 ms |
47316 KB |
Output is correct |
22 |
Correct |
27 ms |
47312 KB |
Output is correct |
23 |
Correct |
28 ms |
47216 KB |
Output is correct |
24 |
Correct |
26 ms |
47316 KB |
Output is correct |
25 |
Correct |
26 ms |
47316 KB |
Output is correct |
26 |
Correct |
31 ms |
47316 KB |
Output is correct |
27 |
Correct |
38 ms |
49056 KB |
Output is correct |
28 |
Correct |
40 ms |
49124 KB |
Output is correct |
29 |
Correct |
37 ms |
49100 KB |
Output is correct |
30 |
Correct |
36 ms |
49204 KB |
Output is correct |
31 |
Correct |
44 ms |
49160 KB |
Output is correct |
32 |
Correct |
38 ms |
49088 KB |
Output is correct |
33 |
Correct |
38 ms |
49032 KB |
Output is correct |
34 |
Correct |
37 ms |
49156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47288 KB |
Output is correct |
2 |
Correct |
27 ms |
47256 KB |
Output is correct |
3 |
Correct |
29 ms |
47288 KB |
Output is correct |
4 |
Correct |
28 ms |
47316 KB |
Output is correct |
5 |
Correct |
27 ms |
47288 KB |
Output is correct |
6 |
Correct |
27 ms |
47272 KB |
Output is correct |
7 |
Correct |
26 ms |
47220 KB |
Output is correct |
8 |
Correct |
32 ms |
47216 KB |
Output is correct |
9 |
Correct |
26 ms |
47308 KB |
Output is correct |
10 |
Correct |
26 ms |
47232 KB |
Output is correct |
11 |
Correct |
27 ms |
47324 KB |
Output is correct |
12 |
Correct |
28 ms |
47284 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
28 ms |
47240 KB |
Output is correct |
15 |
Correct |
28 ms |
47264 KB |
Output is correct |
16 |
Correct |
26 ms |
47308 KB |
Output is correct |
17 |
Correct |
27 ms |
47252 KB |
Output is correct |
18 |
Correct |
29 ms |
47236 KB |
Output is correct |
19 |
Correct |
26 ms |
47284 KB |
Output is correct |
20 |
Correct |
27 ms |
47312 KB |
Output is correct |
21 |
Correct |
26 ms |
47316 KB |
Output is correct |
22 |
Correct |
27 ms |
47312 KB |
Output is correct |
23 |
Correct |
28 ms |
47216 KB |
Output is correct |
24 |
Correct |
26 ms |
47316 KB |
Output is correct |
25 |
Correct |
26 ms |
47316 KB |
Output is correct |
26 |
Correct |
31 ms |
47316 KB |
Output is correct |
27 |
Correct |
38 ms |
49056 KB |
Output is correct |
28 |
Correct |
40 ms |
49124 KB |
Output is correct |
29 |
Correct |
37 ms |
49100 KB |
Output is correct |
30 |
Correct |
36 ms |
49204 KB |
Output is correct |
31 |
Correct |
44 ms |
49160 KB |
Output is correct |
32 |
Correct |
38 ms |
49088 KB |
Output is correct |
33 |
Correct |
38 ms |
49032 KB |
Output is correct |
34 |
Correct |
37 ms |
49156 KB |
Output is correct |
35 |
Correct |
41 ms |
49144 KB |
Output is correct |
36 |
Correct |
39 ms |
49092 KB |
Output is correct |
37 |
Correct |
39 ms |
49144 KB |
Output is correct |
38 |
Correct |
42 ms |
49276 KB |
Output is correct |
39 |
Correct |
41 ms |
49076 KB |
Output is correct |
40 |
Correct |
39 ms |
49260 KB |
Output is correct |
41 |
Correct |
39 ms |
49292 KB |
Output is correct |
42 |
Correct |
38 ms |
49308 KB |
Output is correct |
43 |
Correct |
41 ms |
49356 KB |
Output is correct |
44 |
Correct |
39 ms |
49356 KB |
Output is correct |
45 |
Correct |
38 ms |
49356 KB |
Output is correct |
46 |
Correct |
39 ms |
49356 KB |
Output is correct |
47 |
Correct |
38 ms |
49312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47288 KB |
Output is correct |
2 |
Correct |
27 ms |
47256 KB |
Output is correct |
3 |
Correct |
29 ms |
47288 KB |
Output is correct |
4 |
Correct |
28 ms |
47316 KB |
Output is correct |
5 |
Correct |
27 ms |
47288 KB |
Output is correct |
6 |
Correct |
27 ms |
47272 KB |
Output is correct |
7 |
Correct |
26 ms |
47220 KB |
Output is correct |
8 |
Correct |
32 ms |
47216 KB |
Output is correct |
9 |
Correct |
26 ms |
47308 KB |
Output is correct |
10 |
Correct |
26 ms |
47232 KB |
Output is correct |
11 |
Correct |
27 ms |
47324 KB |
Output is correct |
12 |
Correct |
28 ms |
47284 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
28 ms |
47240 KB |
Output is correct |
15 |
Correct |
28 ms |
47264 KB |
Output is correct |
16 |
Correct |
26 ms |
47308 KB |
Output is correct |
17 |
Correct |
27 ms |
47252 KB |
Output is correct |
18 |
Correct |
29 ms |
47236 KB |
Output is correct |
19 |
Correct |
26 ms |
47284 KB |
Output is correct |
20 |
Correct |
27 ms |
47312 KB |
Output is correct |
21 |
Correct |
26 ms |
47316 KB |
Output is correct |
22 |
Correct |
27 ms |
47312 KB |
Output is correct |
23 |
Correct |
28 ms |
47216 KB |
Output is correct |
24 |
Correct |
26 ms |
47316 KB |
Output is correct |
25 |
Correct |
26 ms |
47316 KB |
Output is correct |
26 |
Correct |
31 ms |
47316 KB |
Output is correct |
27 |
Correct |
38 ms |
49056 KB |
Output is correct |
28 |
Correct |
40 ms |
49124 KB |
Output is correct |
29 |
Correct |
37 ms |
49100 KB |
Output is correct |
30 |
Correct |
36 ms |
49204 KB |
Output is correct |
31 |
Correct |
44 ms |
49160 KB |
Output is correct |
32 |
Correct |
38 ms |
49088 KB |
Output is correct |
33 |
Correct |
38 ms |
49032 KB |
Output is correct |
34 |
Correct |
37 ms |
49156 KB |
Output is correct |
35 |
Correct |
41 ms |
49144 KB |
Output is correct |
36 |
Correct |
39 ms |
49092 KB |
Output is correct |
37 |
Correct |
39 ms |
49144 KB |
Output is correct |
38 |
Correct |
42 ms |
49276 KB |
Output is correct |
39 |
Correct |
41 ms |
49076 KB |
Output is correct |
40 |
Correct |
39 ms |
49260 KB |
Output is correct |
41 |
Correct |
39 ms |
49292 KB |
Output is correct |
42 |
Correct |
38 ms |
49308 KB |
Output is correct |
43 |
Correct |
41 ms |
49356 KB |
Output is correct |
44 |
Correct |
39 ms |
49356 KB |
Output is correct |
45 |
Correct |
38 ms |
49356 KB |
Output is correct |
46 |
Correct |
39 ms |
49356 KB |
Output is correct |
47 |
Correct |
38 ms |
49312 KB |
Output is correct |
48 |
Correct |
166 ms |
64680 KB |
Output is correct |
49 |
Correct |
161 ms |
64660 KB |
Output is correct |
50 |
Correct |
159 ms |
64732 KB |
Output is correct |
51 |
Correct |
151 ms |
64704 KB |
Output is correct |
52 |
Correct |
141 ms |
62236 KB |
Output is correct |
53 |
Correct |
153 ms |
63152 KB |
Output is correct |
54 |
Correct |
151 ms |
61204 KB |
Output is correct |
55 |
Correct |
150 ms |
60868 KB |
Output is correct |
56 |
Correct |
150 ms |
60312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47288 KB |
Output is correct |
2 |
Correct |
27 ms |
47256 KB |
Output is correct |
3 |
Correct |
29 ms |
47288 KB |
Output is correct |
4 |
Correct |
28 ms |
47316 KB |
Output is correct |
5 |
Correct |
27 ms |
47288 KB |
Output is correct |
6 |
Correct |
27 ms |
47272 KB |
Output is correct |
7 |
Correct |
26 ms |
47220 KB |
Output is correct |
8 |
Correct |
32 ms |
47216 KB |
Output is correct |
9 |
Correct |
26 ms |
47308 KB |
Output is correct |
10 |
Correct |
26 ms |
47232 KB |
Output is correct |
11 |
Correct |
27 ms |
47324 KB |
Output is correct |
12 |
Correct |
28 ms |
47284 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
28 ms |
47240 KB |
Output is correct |
15 |
Correct |
28 ms |
47264 KB |
Output is correct |
16 |
Correct |
26 ms |
47308 KB |
Output is correct |
17 |
Correct |
27 ms |
47252 KB |
Output is correct |
18 |
Correct |
29 ms |
47236 KB |
Output is correct |
19 |
Correct |
26 ms |
47284 KB |
Output is correct |
20 |
Correct |
27 ms |
47312 KB |
Output is correct |
21 |
Correct |
26 ms |
47316 KB |
Output is correct |
22 |
Correct |
27 ms |
47312 KB |
Output is correct |
23 |
Correct |
28 ms |
47216 KB |
Output is correct |
24 |
Correct |
26 ms |
47316 KB |
Output is correct |
25 |
Correct |
26 ms |
47316 KB |
Output is correct |
26 |
Correct |
31 ms |
47316 KB |
Output is correct |
27 |
Correct |
38 ms |
49056 KB |
Output is correct |
28 |
Correct |
40 ms |
49124 KB |
Output is correct |
29 |
Correct |
37 ms |
49100 KB |
Output is correct |
30 |
Correct |
36 ms |
49204 KB |
Output is correct |
31 |
Correct |
44 ms |
49160 KB |
Output is correct |
32 |
Correct |
38 ms |
49088 KB |
Output is correct |
33 |
Correct |
38 ms |
49032 KB |
Output is correct |
34 |
Correct |
37 ms |
49156 KB |
Output is correct |
35 |
Correct |
41 ms |
49144 KB |
Output is correct |
36 |
Correct |
39 ms |
49092 KB |
Output is correct |
37 |
Correct |
39 ms |
49144 KB |
Output is correct |
38 |
Correct |
42 ms |
49276 KB |
Output is correct |
39 |
Correct |
41 ms |
49076 KB |
Output is correct |
40 |
Correct |
39 ms |
49260 KB |
Output is correct |
41 |
Correct |
39 ms |
49292 KB |
Output is correct |
42 |
Correct |
38 ms |
49308 KB |
Output is correct |
43 |
Correct |
41 ms |
49356 KB |
Output is correct |
44 |
Correct |
39 ms |
49356 KB |
Output is correct |
45 |
Correct |
38 ms |
49356 KB |
Output is correct |
46 |
Correct |
39 ms |
49356 KB |
Output is correct |
47 |
Correct |
38 ms |
49312 KB |
Output is correct |
48 |
Correct |
166 ms |
64680 KB |
Output is correct |
49 |
Correct |
161 ms |
64660 KB |
Output is correct |
50 |
Correct |
159 ms |
64732 KB |
Output is correct |
51 |
Correct |
151 ms |
64704 KB |
Output is correct |
52 |
Correct |
141 ms |
62236 KB |
Output is correct |
53 |
Correct |
153 ms |
63152 KB |
Output is correct |
54 |
Correct |
151 ms |
61204 KB |
Output is correct |
55 |
Correct |
150 ms |
60868 KB |
Output is correct |
56 |
Correct |
150 ms |
60312 KB |
Output is correct |
57 |
Correct |
1384 ms |
134064 KB |
Output is correct |
58 |
Correct |
1057 ms |
107400 KB |
Output is correct |
59 |
Correct |
1060 ms |
107276 KB |
Output is correct |
60 |
Correct |
1126 ms |
115524 KB |
Output is correct |
61 |
Correct |
1157 ms |
115528 KB |
Output is correct |
62 |
Correct |
456 ms |
88680 KB |
Output is correct |
63 |
Correct |
732 ms |
97628 KB |
Output is correct |
64 |
Correct |
606 ms |
92148 KB |
Output is correct |
65 |
Correct |
293 ms |
77536 KB |
Output is correct |