# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241658 |
2020-06-25T05:19:20 Z |
arnold518 |
Rope (JOI17_rope) |
C++14 |
|
1441 ms |
84732 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
int N, M, A[MAXN+10];
int val[MAXN+10], cnt[MAXN+10], maxv=0, ans[MAXN+10];
vector<int> V[MAXN+10];
void init()
{
int i, j;
memset(val, 0, sizeof(val));
memset(cnt, 0, sizeof(cnt));
for(i=1; i<=M; i++) V[i].clear();
maxv=0;
val[0]=N;
}
void push(int x)
{
val[cnt[x]]--;
cnt[x]++;
val[cnt[x]]++;
maxv=max(maxv, cnt[x]);
}
void pop(int x)
{
val[cnt[x]]--;
if(val[maxv]==0) maxv--;
cnt[x]--;
val[cnt[x]]++;
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=N; i++) scanf("%d", &A[i]);
for(i=1; i<=M; i++) ans[i]=987654321;
init();
for(i=1; i<=N; i++) push(A[i]);
for(i=1; i<=N; i+=2)
{
int a, b;
if(i+1<=N)
{
a=A[i], b=A[i+1];
if(a==b) continue;
V[a].push_back(b);
V[b].push_back(a);
}
}
for(i=1; i<=M; i++)
{
int t=cnt[i];
for(j=1; j<=t; j++) pop(i);
for(auto it : V[i]) pop(it);
ans[i]=min(ans[i], N-t-maxv);
for(auto it : V[i]) push(it);
for(j=1; j<=t; j++) push(i);
}
init();
for(i=1; i<=N; i++) push(A[i]);
for(i=2; i<=N; i+=2)
{
int a, b;
if(i+1<=N)
{
a=A[i], b=A[i+1];
if(a==b) continue;
V[a].push_back(b);
V[b].push_back(a);
}
}
for(i=1; i<=M; i++)
{
int t=cnt[i];
for(j=1; j<=t; j++) pop(i);
for(auto it : V[i]) pop(it);
ans[i]=min(ans[i], N-t-maxv);
for(auto it : V[i]) push(it);
for(j=1; j<=t; j++) push(i);
}
for(i=1; i<=M; i++) printf("%d\n", ans[i]);
}
Compilation message
rope.cpp: In function 'void init()':
rope.cpp:16:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
rope.cpp: In function 'int main()':
rope.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
rope.cpp:45:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31616 KB |
Output is correct |
2 |
Correct |
25 ms |
31616 KB |
Output is correct |
3 |
Correct |
25 ms |
31616 KB |
Output is correct |
4 |
Correct |
24 ms |
31616 KB |
Output is correct |
5 |
Correct |
24 ms |
31616 KB |
Output is correct |
6 |
Correct |
25 ms |
31608 KB |
Output is correct |
7 |
Correct |
25 ms |
31744 KB |
Output is correct |
8 |
Correct |
24 ms |
31616 KB |
Output is correct |
9 |
Correct |
25 ms |
31616 KB |
Output is correct |
10 |
Correct |
24 ms |
31616 KB |
Output is correct |
11 |
Correct |
24 ms |
31616 KB |
Output is correct |
12 |
Correct |
24 ms |
31488 KB |
Output is correct |
13 |
Correct |
24 ms |
31616 KB |
Output is correct |
14 |
Correct |
23 ms |
31616 KB |
Output is correct |
15 |
Correct |
24 ms |
31616 KB |
Output is correct |
16 |
Correct |
25 ms |
31616 KB |
Output is correct |
17 |
Correct |
27 ms |
31616 KB |
Output is correct |
18 |
Correct |
29 ms |
31612 KB |
Output is correct |
19 |
Correct |
24 ms |
31616 KB |
Output is correct |
20 |
Correct |
24 ms |
31616 KB |
Output is correct |
21 |
Correct |
26 ms |
31616 KB |
Output is correct |
22 |
Correct |
24 ms |
31616 KB |
Output is correct |
23 |
Correct |
24 ms |
31616 KB |
Output is correct |
24 |
Correct |
25 ms |
31616 KB |
Output is correct |
25 |
Correct |
29 ms |
31616 KB |
Output is correct |
26 |
Correct |
24 ms |
31616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31616 KB |
Output is correct |
2 |
Correct |
25 ms |
31616 KB |
Output is correct |
3 |
Correct |
25 ms |
31616 KB |
Output is correct |
4 |
Correct |
24 ms |
31616 KB |
Output is correct |
5 |
Correct |
24 ms |
31616 KB |
Output is correct |
6 |
Correct |
25 ms |
31608 KB |
Output is correct |
7 |
Correct |
25 ms |
31744 KB |
Output is correct |
8 |
Correct |
24 ms |
31616 KB |
Output is correct |
9 |
Correct |
25 ms |
31616 KB |
Output is correct |
10 |
Correct |
24 ms |
31616 KB |
Output is correct |
11 |
Correct |
24 ms |
31616 KB |
Output is correct |
12 |
Correct |
24 ms |
31488 KB |
Output is correct |
13 |
Correct |
24 ms |
31616 KB |
Output is correct |
14 |
Correct |
23 ms |
31616 KB |
Output is correct |
15 |
Correct |
24 ms |
31616 KB |
Output is correct |
16 |
Correct |
25 ms |
31616 KB |
Output is correct |
17 |
Correct |
27 ms |
31616 KB |
Output is correct |
18 |
Correct |
29 ms |
31612 KB |
Output is correct |
19 |
Correct |
24 ms |
31616 KB |
Output is correct |
20 |
Correct |
24 ms |
31616 KB |
Output is correct |
21 |
Correct |
26 ms |
31616 KB |
Output is correct |
22 |
Correct |
24 ms |
31616 KB |
Output is correct |
23 |
Correct |
24 ms |
31616 KB |
Output is correct |
24 |
Correct |
25 ms |
31616 KB |
Output is correct |
25 |
Correct |
29 ms |
31616 KB |
Output is correct |
26 |
Correct |
24 ms |
31616 KB |
Output is correct |
27 |
Correct |
39 ms |
32888 KB |
Output is correct |
28 |
Correct |
39 ms |
32760 KB |
Output is correct |
29 |
Correct |
40 ms |
32768 KB |
Output is correct |
30 |
Correct |
39 ms |
32640 KB |
Output is correct |
31 |
Correct |
40 ms |
32896 KB |
Output is correct |
32 |
Correct |
39 ms |
32768 KB |
Output is correct |
33 |
Correct |
39 ms |
32760 KB |
Output is correct |
34 |
Correct |
39 ms |
32640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31616 KB |
Output is correct |
2 |
Correct |
25 ms |
31616 KB |
Output is correct |
3 |
Correct |
25 ms |
31616 KB |
Output is correct |
4 |
Correct |
24 ms |
31616 KB |
Output is correct |
5 |
Correct |
24 ms |
31616 KB |
Output is correct |
6 |
Correct |
25 ms |
31608 KB |
Output is correct |
7 |
Correct |
25 ms |
31744 KB |
Output is correct |
8 |
Correct |
24 ms |
31616 KB |
Output is correct |
9 |
Correct |
25 ms |
31616 KB |
Output is correct |
10 |
Correct |
24 ms |
31616 KB |
Output is correct |
11 |
Correct |
24 ms |
31616 KB |
Output is correct |
12 |
Correct |
24 ms |
31488 KB |
Output is correct |
13 |
Correct |
24 ms |
31616 KB |
Output is correct |
14 |
Correct |
23 ms |
31616 KB |
Output is correct |
15 |
Correct |
24 ms |
31616 KB |
Output is correct |
16 |
Correct |
25 ms |
31616 KB |
Output is correct |
17 |
Correct |
27 ms |
31616 KB |
Output is correct |
18 |
Correct |
29 ms |
31612 KB |
Output is correct |
19 |
Correct |
24 ms |
31616 KB |
Output is correct |
20 |
Correct |
24 ms |
31616 KB |
Output is correct |
21 |
Correct |
26 ms |
31616 KB |
Output is correct |
22 |
Correct |
24 ms |
31616 KB |
Output is correct |
23 |
Correct |
24 ms |
31616 KB |
Output is correct |
24 |
Correct |
25 ms |
31616 KB |
Output is correct |
25 |
Correct |
29 ms |
31616 KB |
Output is correct |
26 |
Correct |
24 ms |
31616 KB |
Output is correct |
27 |
Correct |
39 ms |
32888 KB |
Output is correct |
28 |
Correct |
39 ms |
32760 KB |
Output is correct |
29 |
Correct |
40 ms |
32768 KB |
Output is correct |
30 |
Correct |
39 ms |
32640 KB |
Output is correct |
31 |
Correct |
40 ms |
32896 KB |
Output is correct |
32 |
Correct |
39 ms |
32768 KB |
Output is correct |
33 |
Correct |
39 ms |
32760 KB |
Output is correct |
34 |
Correct |
39 ms |
32640 KB |
Output is correct |
35 |
Correct |
45 ms |
33024 KB |
Output is correct |
36 |
Correct |
44 ms |
33016 KB |
Output is correct |
37 |
Correct |
43 ms |
33024 KB |
Output is correct |
38 |
Correct |
42 ms |
33016 KB |
Output is correct |
39 |
Correct |
42 ms |
33024 KB |
Output is correct |
40 |
Correct |
42 ms |
33024 KB |
Output is correct |
41 |
Correct |
45 ms |
33020 KB |
Output is correct |
42 |
Correct |
41 ms |
33016 KB |
Output is correct |
43 |
Correct |
43 ms |
33016 KB |
Output is correct |
44 |
Correct |
44 ms |
33016 KB |
Output is correct |
45 |
Correct |
42 ms |
33024 KB |
Output is correct |
46 |
Correct |
43 ms |
33016 KB |
Output is correct |
47 |
Correct |
41 ms |
33024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31616 KB |
Output is correct |
2 |
Correct |
25 ms |
31616 KB |
Output is correct |
3 |
Correct |
25 ms |
31616 KB |
Output is correct |
4 |
Correct |
24 ms |
31616 KB |
Output is correct |
5 |
Correct |
24 ms |
31616 KB |
Output is correct |
6 |
Correct |
25 ms |
31608 KB |
Output is correct |
7 |
Correct |
25 ms |
31744 KB |
Output is correct |
8 |
Correct |
24 ms |
31616 KB |
Output is correct |
9 |
Correct |
25 ms |
31616 KB |
Output is correct |
10 |
Correct |
24 ms |
31616 KB |
Output is correct |
11 |
Correct |
24 ms |
31616 KB |
Output is correct |
12 |
Correct |
24 ms |
31488 KB |
Output is correct |
13 |
Correct |
24 ms |
31616 KB |
Output is correct |
14 |
Correct |
23 ms |
31616 KB |
Output is correct |
15 |
Correct |
24 ms |
31616 KB |
Output is correct |
16 |
Correct |
25 ms |
31616 KB |
Output is correct |
17 |
Correct |
27 ms |
31616 KB |
Output is correct |
18 |
Correct |
29 ms |
31612 KB |
Output is correct |
19 |
Correct |
24 ms |
31616 KB |
Output is correct |
20 |
Correct |
24 ms |
31616 KB |
Output is correct |
21 |
Correct |
26 ms |
31616 KB |
Output is correct |
22 |
Correct |
24 ms |
31616 KB |
Output is correct |
23 |
Correct |
24 ms |
31616 KB |
Output is correct |
24 |
Correct |
25 ms |
31616 KB |
Output is correct |
25 |
Correct |
29 ms |
31616 KB |
Output is correct |
26 |
Correct |
24 ms |
31616 KB |
Output is correct |
27 |
Correct |
39 ms |
32888 KB |
Output is correct |
28 |
Correct |
39 ms |
32760 KB |
Output is correct |
29 |
Correct |
40 ms |
32768 KB |
Output is correct |
30 |
Correct |
39 ms |
32640 KB |
Output is correct |
31 |
Correct |
40 ms |
32896 KB |
Output is correct |
32 |
Correct |
39 ms |
32768 KB |
Output is correct |
33 |
Correct |
39 ms |
32760 KB |
Output is correct |
34 |
Correct |
39 ms |
32640 KB |
Output is correct |
35 |
Correct |
45 ms |
33024 KB |
Output is correct |
36 |
Correct |
44 ms |
33016 KB |
Output is correct |
37 |
Correct |
43 ms |
33024 KB |
Output is correct |
38 |
Correct |
42 ms |
33016 KB |
Output is correct |
39 |
Correct |
42 ms |
33024 KB |
Output is correct |
40 |
Correct |
42 ms |
33024 KB |
Output is correct |
41 |
Correct |
45 ms |
33020 KB |
Output is correct |
42 |
Correct |
41 ms |
33016 KB |
Output is correct |
43 |
Correct |
43 ms |
33016 KB |
Output is correct |
44 |
Correct |
44 ms |
33016 KB |
Output is correct |
45 |
Correct |
42 ms |
33024 KB |
Output is correct |
46 |
Correct |
43 ms |
33016 KB |
Output is correct |
47 |
Correct |
41 ms |
33024 KB |
Output is correct |
48 |
Correct |
228 ms |
46712 KB |
Output is correct |
49 |
Correct |
225 ms |
46804 KB |
Output is correct |
50 |
Correct |
224 ms |
46712 KB |
Output is correct |
51 |
Correct |
215 ms |
46328 KB |
Output is correct |
52 |
Correct |
215 ms |
45048 KB |
Output is correct |
53 |
Correct |
210 ms |
45944 KB |
Output is correct |
54 |
Correct |
213 ms |
45048 KB |
Output is correct |
55 |
Correct |
221 ms |
44792 KB |
Output is correct |
56 |
Correct |
206 ms |
44512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
31616 KB |
Output is correct |
2 |
Correct |
25 ms |
31616 KB |
Output is correct |
3 |
Correct |
25 ms |
31616 KB |
Output is correct |
4 |
Correct |
24 ms |
31616 KB |
Output is correct |
5 |
Correct |
24 ms |
31616 KB |
Output is correct |
6 |
Correct |
25 ms |
31608 KB |
Output is correct |
7 |
Correct |
25 ms |
31744 KB |
Output is correct |
8 |
Correct |
24 ms |
31616 KB |
Output is correct |
9 |
Correct |
25 ms |
31616 KB |
Output is correct |
10 |
Correct |
24 ms |
31616 KB |
Output is correct |
11 |
Correct |
24 ms |
31616 KB |
Output is correct |
12 |
Correct |
24 ms |
31488 KB |
Output is correct |
13 |
Correct |
24 ms |
31616 KB |
Output is correct |
14 |
Correct |
23 ms |
31616 KB |
Output is correct |
15 |
Correct |
24 ms |
31616 KB |
Output is correct |
16 |
Correct |
25 ms |
31616 KB |
Output is correct |
17 |
Correct |
27 ms |
31616 KB |
Output is correct |
18 |
Correct |
29 ms |
31612 KB |
Output is correct |
19 |
Correct |
24 ms |
31616 KB |
Output is correct |
20 |
Correct |
24 ms |
31616 KB |
Output is correct |
21 |
Correct |
26 ms |
31616 KB |
Output is correct |
22 |
Correct |
24 ms |
31616 KB |
Output is correct |
23 |
Correct |
24 ms |
31616 KB |
Output is correct |
24 |
Correct |
25 ms |
31616 KB |
Output is correct |
25 |
Correct |
29 ms |
31616 KB |
Output is correct |
26 |
Correct |
24 ms |
31616 KB |
Output is correct |
27 |
Correct |
39 ms |
32888 KB |
Output is correct |
28 |
Correct |
39 ms |
32760 KB |
Output is correct |
29 |
Correct |
40 ms |
32768 KB |
Output is correct |
30 |
Correct |
39 ms |
32640 KB |
Output is correct |
31 |
Correct |
40 ms |
32896 KB |
Output is correct |
32 |
Correct |
39 ms |
32768 KB |
Output is correct |
33 |
Correct |
39 ms |
32760 KB |
Output is correct |
34 |
Correct |
39 ms |
32640 KB |
Output is correct |
35 |
Correct |
45 ms |
33024 KB |
Output is correct |
36 |
Correct |
44 ms |
33016 KB |
Output is correct |
37 |
Correct |
43 ms |
33024 KB |
Output is correct |
38 |
Correct |
42 ms |
33016 KB |
Output is correct |
39 |
Correct |
42 ms |
33024 KB |
Output is correct |
40 |
Correct |
42 ms |
33024 KB |
Output is correct |
41 |
Correct |
45 ms |
33020 KB |
Output is correct |
42 |
Correct |
41 ms |
33016 KB |
Output is correct |
43 |
Correct |
43 ms |
33016 KB |
Output is correct |
44 |
Correct |
44 ms |
33016 KB |
Output is correct |
45 |
Correct |
42 ms |
33024 KB |
Output is correct |
46 |
Correct |
43 ms |
33016 KB |
Output is correct |
47 |
Correct |
41 ms |
33024 KB |
Output is correct |
48 |
Correct |
228 ms |
46712 KB |
Output is correct |
49 |
Correct |
225 ms |
46804 KB |
Output is correct |
50 |
Correct |
224 ms |
46712 KB |
Output is correct |
51 |
Correct |
215 ms |
46328 KB |
Output is correct |
52 |
Correct |
215 ms |
45048 KB |
Output is correct |
53 |
Correct |
210 ms |
45944 KB |
Output is correct |
54 |
Correct |
213 ms |
45048 KB |
Output is correct |
55 |
Correct |
221 ms |
44792 KB |
Output is correct |
56 |
Correct |
206 ms |
44512 KB |
Output is correct |
57 |
Correct |
1441 ms |
84732 KB |
Output is correct |
58 |
Correct |
1124 ms |
67832 KB |
Output is correct |
59 |
Correct |
1176 ms |
67552 KB |
Output is correct |
60 |
Correct |
1155 ms |
71780 KB |
Output is correct |
61 |
Correct |
1012 ms |
72004 KB |
Output is correct |
62 |
Correct |
462 ms |
57848 KB |
Output is correct |
63 |
Correct |
652 ms |
62456 KB |
Output is correct |
64 |
Correct |
669 ms |
59608 KB |
Output is correct |
65 |
Correct |
324 ms |
51884 KB |
Output is correct |