# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
51317 |
2018-06-17T13:04:42 Z |
ho94949 |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
13580 KB |
#include<bits/stdc++.h>
using namespace std;
int N, K;
int arr[1010101];
int ans[1010101];
int cnt[1010101];
int evalodd(int c)
{
memset(cnt+1, 0, sizeof(int)*K);
int ans = 0;
if(arr[0] != c) cnt[arr[0]]++;
else ++ans;
for(int i=0; i<(N-1)/2; ++i)
{
int l = arr[2*i+1], r = arr[2*i+2];
if(l == c && r == c)
ans += 2;
else if(l == c || r == c)
ans++;
else
cnt[l]++, cnt[r]++;
}
if(N%2==0)
{
if(arr[N-1] != c)
cnt[arr[N-1]]++;
else
++ans;
}
/*
puts("==O==");
printf("%d\n", c);
for(int i=1; i<=K; ++i)
printf("%d ", cnt[i]);
printf("\n%d\n", ans);
puts("=====");
*/
return ans + *max_element(cnt+1, cnt+K+1);
}
int evaleven(int c)
{
memset(cnt+1, 0, sizeof(int)*K);
int ans = 0;
for(int i=0; i<N/2; ++i)
{
int l = arr[2*i], r = arr[2*i+1];
if(l == c && r == c)
ans += 2;
else if(l == c || r == c)
ans++;
else
cnt[l]++, cnt[r]++;
}
if(N%2==1)
{
if(arr[N-1] != c)
cnt[arr[N-1]]++;
else
++ans;
}
/*
puts("==E==");
printf("%d\n", c);
for(int i=1; i<=K; ++i)
printf("%d ", cnt[i]);
printf("\n%d\n", ans);
puts("=====");
*/
return ans + *max_element(cnt+1, cnt+K+1);
}
int main()
{
scanf("%d%d", &N, &K);
for(int i=0; i<N; ++i) scanf("%d", arr+i);
for(int i=1; i<=K; ++i)
ans[i] = 0x3f3f3f3f;
for(int i=1; i<=K; ++i)
printf("%d\n", N-max(evaleven(i), evalodd(i)));
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &K);
~~~~~^~~~~~~~~~~~~~~~
rope.cpp:74:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<N; ++i) scanf("%d", arr+i);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
700 KB |
Output is correct |
13 |
Correct |
2 ms |
700 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
700 KB |
Output is correct |
13 |
Correct |
2 ms |
700 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
17 ms |
988 KB |
Output is correct |
28 |
Correct |
17 ms |
996 KB |
Output is correct |
29 |
Correct |
16 ms |
1012 KB |
Output is correct |
30 |
Correct |
17 ms |
1012 KB |
Output is correct |
31 |
Correct |
16 ms |
1012 KB |
Output is correct |
32 |
Correct |
14 ms |
1012 KB |
Output is correct |
33 |
Correct |
16 ms |
1012 KB |
Output is correct |
34 |
Correct |
17 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
700 KB |
Output is correct |
13 |
Correct |
2 ms |
700 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
17 ms |
988 KB |
Output is correct |
28 |
Correct |
17 ms |
996 KB |
Output is correct |
29 |
Correct |
16 ms |
1012 KB |
Output is correct |
30 |
Correct |
17 ms |
1012 KB |
Output is correct |
31 |
Correct |
16 ms |
1012 KB |
Output is correct |
32 |
Correct |
14 ms |
1012 KB |
Output is correct |
33 |
Correct |
16 ms |
1012 KB |
Output is correct |
34 |
Correct |
17 ms |
1132 KB |
Output is correct |
35 |
Correct |
131 ms |
1148 KB |
Output is correct |
36 |
Correct |
139 ms |
1324 KB |
Output is correct |
37 |
Correct |
125 ms |
1928 KB |
Output is correct |
38 |
Correct |
116 ms |
2200 KB |
Output is correct |
39 |
Correct |
119 ms |
2568 KB |
Output is correct |
40 |
Correct |
137 ms |
2928 KB |
Output is correct |
41 |
Correct |
140 ms |
3440 KB |
Output is correct |
42 |
Correct |
128 ms |
3684 KB |
Output is correct |
43 |
Correct |
104 ms |
4052 KB |
Output is correct |
44 |
Correct |
135 ms |
4292 KB |
Output is correct |
45 |
Correct |
137 ms |
4772 KB |
Output is correct |
46 |
Correct |
116 ms |
5032 KB |
Output is correct |
47 |
Correct |
94 ms |
5396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
700 KB |
Output is correct |
13 |
Correct |
2 ms |
700 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
17 ms |
988 KB |
Output is correct |
28 |
Correct |
17 ms |
996 KB |
Output is correct |
29 |
Correct |
16 ms |
1012 KB |
Output is correct |
30 |
Correct |
17 ms |
1012 KB |
Output is correct |
31 |
Correct |
16 ms |
1012 KB |
Output is correct |
32 |
Correct |
14 ms |
1012 KB |
Output is correct |
33 |
Correct |
16 ms |
1012 KB |
Output is correct |
34 |
Correct |
17 ms |
1132 KB |
Output is correct |
35 |
Correct |
131 ms |
1148 KB |
Output is correct |
36 |
Correct |
139 ms |
1324 KB |
Output is correct |
37 |
Correct |
125 ms |
1928 KB |
Output is correct |
38 |
Correct |
116 ms |
2200 KB |
Output is correct |
39 |
Correct |
119 ms |
2568 KB |
Output is correct |
40 |
Correct |
137 ms |
2928 KB |
Output is correct |
41 |
Correct |
140 ms |
3440 KB |
Output is correct |
42 |
Correct |
128 ms |
3684 KB |
Output is correct |
43 |
Correct |
104 ms |
4052 KB |
Output is correct |
44 |
Correct |
135 ms |
4292 KB |
Output is correct |
45 |
Correct |
137 ms |
4772 KB |
Output is correct |
46 |
Correct |
116 ms |
5032 KB |
Output is correct |
47 |
Correct |
94 ms |
5396 KB |
Output is correct |
48 |
Execution timed out |
2552 ms |
13580 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
480 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
700 KB |
Output is correct |
13 |
Correct |
2 ms |
700 KB |
Output is correct |
14 |
Correct |
2 ms |
700 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
17 ms |
988 KB |
Output is correct |
28 |
Correct |
17 ms |
996 KB |
Output is correct |
29 |
Correct |
16 ms |
1012 KB |
Output is correct |
30 |
Correct |
17 ms |
1012 KB |
Output is correct |
31 |
Correct |
16 ms |
1012 KB |
Output is correct |
32 |
Correct |
14 ms |
1012 KB |
Output is correct |
33 |
Correct |
16 ms |
1012 KB |
Output is correct |
34 |
Correct |
17 ms |
1132 KB |
Output is correct |
35 |
Correct |
131 ms |
1148 KB |
Output is correct |
36 |
Correct |
139 ms |
1324 KB |
Output is correct |
37 |
Correct |
125 ms |
1928 KB |
Output is correct |
38 |
Correct |
116 ms |
2200 KB |
Output is correct |
39 |
Correct |
119 ms |
2568 KB |
Output is correct |
40 |
Correct |
137 ms |
2928 KB |
Output is correct |
41 |
Correct |
140 ms |
3440 KB |
Output is correct |
42 |
Correct |
128 ms |
3684 KB |
Output is correct |
43 |
Correct |
104 ms |
4052 KB |
Output is correct |
44 |
Correct |
135 ms |
4292 KB |
Output is correct |
45 |
Correct |
137 ms |
4772 KB |
Output is correct |
46 |
Correct |
116 ms |
5032 KB |
Output is correct |
47 |
Correct |
94 ms |
5396 KB |
Output is correct |
48 |
Execution timed out |
2552 ms |
13580 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |