# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
128648 |
2019-07-11T07:58:59 Z |
송준혁(#3162) |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
131796 KB |
#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[1010101];
vector<int> O[1010101], E[1010101];
int cnt[1010101];
int T[4040404];
void init(int id, int s, int e){
if (s == e){
T[id] = cnt[s];
return;
}
int mid = (s+e)/2;
init(id*2, s, mid);
init(id*2+1, mid+1, e);
T[id] = max(T[id*2], T[id*2+1]);
}
void update(int id, int s, int e, int t, int v){
if (e < t || t < s) return;
if (s == e){
T[id] += v;
return;
}
int mid = (s+e)/2;
update(id*2, s, mid, t, v);
update(id*2+1, mid+1, e, t, v);
T[id] = max(T[id*2], T[id*2+1]);
}
int RMQ(int id, int s, int e, int ts, int te){
if (e < ts || te < s) return 0;
if (ts <= s && e <= te) return T[id];
int mid = (s+e)/2;
return max(RMQ(id*2, s, mid, ts, te), RMQ(id*2+1, mid+1, e, ts, te));
}
int main(){
scanf("%d %d", &N, &M);
for (int i=1; i<=N; i++){
scanf("%d", &A[i]);
cnt[A[i]]++;
}
for (int i=1; i<N; i++){
if (A[i] == A[i+1]) continue;
if (i & 1){
E[A[i]].push_back(A[i+1]);
E[A[i+1]].push_back(A[i]);
}
else{
O[A[i]].push_back(A[i+1]);
O[A[i+1]].push_back(A[i]);
}
}
init(1, 1, M);
for (int i=1; i<=M; i++){
for (int x : O[i]) update(1, 1, M, x, -1);
int oret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
for (int x : O[i]) update(1, 1, M, x, 1);
for (int x : E[i]) update(1, 1, M, x, -1);
int eret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
for (int x : E[i]) update(1, 1, M, x, 1);
printf("%d\n", N - max(oret, eret));
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:41: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:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47736 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47736 KB |
Output is correct |
5 |
Correct |
46 ms |
47736 KB |
Output is correct |
6 |
Correct |
45 ms |
47736 KB |
Output is correct |
7 |
Correct |
54 ms |
47736 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
45 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47736 KB |
Output is correct |
14 |
Correct |
46 ms |
47736 KB |
Output is correct |
15 |
Correct |
47 ms |
47796 KB |
Output is correct |
16 |
Correct |
48 ms |
47736 KB |
Output is correct |
17 |
Correct |
45 ms |
47736 KB |
Output is correct |
18 |
Correct |
46 ms |
47736 KB |
Output is correct |
19 |
Correct |
47 ms |
47836 KB |
Output is correct |
20 |
Correct |
45 ms |
47736 KB |
Output is correct |
21 |
Correct |
45 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47864 KB |
Output is correct |
23 |
Correct |
45 ms |
47820 KB |
Output is correct |
24 |
Correct |
45 ms |
47792 KB |
Output is correct |
25 |
Correct |
46 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47736 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47736 KB |
Output is correct |
5 |
Correct |
46 ms |
47736 KB |
Output is correct |
6 |
Correct |
45 ms |
47736 KB |
Output is correct |
7 |
Correct |
54 ms |
47736 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
45 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47736 KB |
Output is correct |
14 |
Correct |
46 ms |
47736 KB |
Output is correct |
15 |
Correct |
47 ms |
47796 KB |
Output is correct |
16 |
Correct |
48 ms |
47736 KB |
Output is correct |
17 |
Correct |
45 ms |
47736 KB |
Output is correct |
18 |
Correct |
46 ms |
47736 KB |
Output is correct |
19 |
Correct |
47 ms |
47836 KB |
Output is correct |
20 |
Correct |
45 ms |
47736 KB |
Output is correct |
21 |
Correct |
45 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47864 KB |
Output is correct |
23 |
Correct |
45 ms |
47820 KB |
Output is correct |
24 |
Correct |
45 ms |
47792 KB |
Output is correct |
25 |
Correct |
46 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47948 KB |
Output is correct |
27 |
Correct |
72 ms |
49272 KB |
Output is correct |
28 |
Correct |
64 ms |
49144 KB |
Output is correct |
29 |
Correct |
77 ms |
49220 KB |
Output is correct |
30 |
Correct |
66 ms |
49016 KB |
Output is correct |
31 |
Correct |
72 ms |
49400 KB |
Output is correct |
32 |
Correct |
64 ms |
49144 KB |
Output is correct |
33 |
Correct |
71 ms |
49272 KB |
Output is correct |
34 |
Correct |
66 ms |
48976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47736 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47736 KB |
Output is correct |
5 |
Correct |
46 ms |
47736 KB |
Output is correct |
6 |
Correct |
45 ms |
47736 KB |
Output is correct |
7 |
Correct |
54 ms |
47736 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
45 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47736 KB |
Output is correct |
14 |
Correct |
46 ms |
47736 KB |
Output is correct |
15 |
Correct |
47 ms |
47796 KB |
Output is correct |
16 |
Correct |
48 ms |
47736 KB |
Output is correct |
17 |
Correct |
45 ms |
47736 KB |
Output is correct |
18 |
Correct |
46 ms |
47736 KB |
Output is correct |
19 |
Correct |
47 ms |
47836 KB |
Output is correct |
20 |
Correct |
45 ms |
47736 KB |
Output is correct |
21 |
Correct |
45 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47864 KB |
Output is correct |
23 |
Correct |
45 ms |
47820 KB |
Output is correct |
24 |
Correct |
45 ms |
47792 KB |
Output is correct |
25 |
Correct |
46 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47948 KB |
Output is correct |
27 |
Correct |
72 ms |
49272 KB |
Output is correct |
28 |
Correct |
64 ms |
49144 KB |
Output is correct |
29 |
Correct |
77 ms |
49220 KB |
Output is correct |
30 |
Correct |
66 ms |
49016 KB |
Output is correct |
31 |
Correct |
72 ms |
49400 KB |
Output is correct |
32 |
Correct |
64 ms |
49144 KB |
Output is correct |
33 |
Correct |
71 ms |
49272 KB |
Output is correct |
34 |
Correct |
66 ms |
48976 KB |
Output is correct |
35 |
Correct |
109 ms |
49272 KB |
Output is correct |
36 |
Correct |
107 ms |
49248 KB |
Output is correct |
37 |
Correct |
107 ms |
49376 KB |
Output is correct |
38 |
Correct |
107 ms |
49272 KB |
Output is correct |
39 |
Correct |
107 ms |
49332 KB |
Output is correct |
40 |
Correct |
101 ms |
49404 KB |
Output is correct |
41 |
Correct |
102 ms |
49452 KB |
Output is correct |
42 |
Correct |
98 ms |
49440 KB |
Output is correct |
43 |
Correct |
98 ms |
49528 KB |
Output is correct |
44 |
Correct |
101 ms |
49400 KB |
Output is correct |
45 |
Correct |
101 ms |
49532 KB |
Output is correct |
46 |
Correct |
99 ms |
49400 KB |
Output is correct |
47 |
Correct |
97 ms |
49400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47736 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47736 KB |
Output is correct |
5 |
Correct |
46 ms |
47736 KB |
Output is correct |
6 |
Correct |
45 ms |
47736 KB |
Output is correct |
7 |
Correct |
54 ms |
47736 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
45 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47736 KB |
Output is correct |
14 |
Correct |
46 ms |
47736 KB |
Output is correct |
15 |
Correct |
47 ms |
47796 KB |
Output is correct |
16 |
Correct |
48 ms |
47736 KB |
Output is correct |
17 |
Correct |
45 ms |
47736 KB |
Output is correct |
18 |
Correct |
46 ms |
47736 KB |
Output is correct |
19 |
Correct |
47 ms |
47836 KB |
Output is correct |
20 |
Correct |
45 ms |
47736 KB |
Output is correct |
21 |
Correct |
45 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47864 KB |
Output is correct |
23 |
Correct |
45 ms |
47820 KB |
Output is correct |
24 |
Correct |
45 ms |
47792 KB |
Output is correct |
25 |
Correct |
46 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47948 KB |
Output is correct |
27 |
Correct |
72 ms |
49272 KB |
Output is correct |
28 |
Correct |
64 ms |
49144 KB |
Output is correct |
29 |
Correct |
77 ms |
49220 KB |
Output is correct |
30 |
Correct |
66 ms |
49016 KB |
Output is correct |
31 |
Correct |
72 ms |
49400 KB |
Output is correct |
32 |
Correct |
64 ms |
49144 KB |
Output is correct |
33 |
Correct |
71 ms |
49272 KB |
Output is correct |
34 |
Correct |
66 ms |
48976 KB |
Output is correct |
35 |
Correct |
109 ms |
49272 KB |
Output is correct |
36 |
Correct |
107 ms |
49248 KB |
Output is correct |
37 |
Correct |
107 ms |
49376 KB |
Output is correct |
38 |
Correct |
107 ms |
49272 KB |
Output is correct |
39 |
Correct |
107 ms |
49332 KB |
Output is correct |
40 |
Correct |
101 ms |
49404 KB |
Output is correct |
41 |
Correct |
102 ms |
49452 KB |
Output is correct |
42 |
Correct |
98 ms |
49440 KB |
Output is correct |
43 |
Correct |
98 ms |
49528 KB |
Output is correct |
44 |
Correct |
101 ms |
49400 KB |
Output is correct |
45 |
Correct |
101 ms |
49532 KB |
Output is correct |
46 |
Correct |
99 ms |
49400 KB |
Output is correct |
47 |
Correct |
97 ms |
49400 KB |
Output is correct |
48 |
Correct |
830 ms |
65340 KB |
Output is correct |
49 |
Correct |
832 ms |
65012 KB |
Output is correct |
50 |
Correct |
839 ms |
65016 KB |
Output is correct |
51 |
Correct |
763 ms |
64864 KB |
Output is correct |
52 |
Correct |
715 ms |
62712 KB |
Output is correct |
53 |
Correct |
788 ms |
63412 KB |
Output is correct |
54 |
Correct |
773 ms |
61576 KB |
Output is correct |
55 |
Correct |
777 ms |
61072 KB |
Output is correct |
56 |
Correct |
768 ms |
60536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47736 KB |
Output is correct |
3 |
Correct |
45 ms |
47736 KB |
Output is correct |
4 |
Correct |
45 ms |
47736 KB |
Output is correct |
5 |
Correct |
46 ms |
47736 KB |
Output is correct |
6 |
Correct |
45 ms |
47736 KB |
Output is correct |
7 |
Correct |
54 ms |
47736 KB |
Output is correct |
8 |
Correct |
45 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47736 KB |
Output is correct |
10 |
Correct |
45 ms |
47736 KB |
Output is correct |
11 |
Correct |
45 ms |
47736 KB |
Output is correct |
12 |
Correct |
45 ms |
47736 KB |
Output is correct |
13 |
Correct |
45 ms |
47736 KB |
Output is correct |
14 |
Correct |
46 ms |
47736 KB |
Output is correct |
15 |
Correct |
47 ms |
47796 KB |
Output is correct |
16 |
Correct |
48 ms |
47736 KB |
Output is correct |
17 |
Correct |
45 ms |
47736 KB |
Output is correct |
18 |
Correct |
46 ms |
47736 KB |
Output is correct |
19 |
Correct |
47 ms |
47836 KB |
Output is correct |
20 |
Correct |
45 ms |
47736 KB |
Output is correct |
21 |
Correct |
45 ms |
47736 KB |
Output is correct |
22 |
Correct |
45 ms |
47864 KB |
Output is correct |
23 |
Correct |
45 ms |
47820 KB |
Output is correct |
24 |
Correct |
45 ms |
47792 KB |
Output is correct |
25 |
Correct |
46 ms |
47736 KB |
Output is correct |
26 |
Correct |
46 ms |
47948 KB |
Output is correct |
27 |
Correct |
72 ms |
49272 KB |
Output is correct |
28 |
Correct |
64 ms |
49144 KB |
Output is correct |
29 |
Correct |
77 ms |
49220 KB |
Output is correct |
30 |
Correct |
66 ms |
49016 KB |
Output is correct |
31 |
Correct |
72 ms |
49400 KB |
Output is correct |
32 |
Correct |
64 ms |
49144 KB |
Output is correct |
33 |
Correct |
71 ms |
49272 KB |
Output is correct |
34 |
Correct |
66 ms |
48976 KB |
Output is correct |
35 |
Correct |
109 ms |
49272 KB |
Output is correct |
36 |
Correct |
107 ms |
49248 KB |
Output is correct |
37 |
Correct |
107 ms |
49376 KB |
Output is correct |
38 |
Correct |
107 ms |
49272 KB |
Output is correct |
39 |
Correct |
107 ms |
49332 KB |
Output is correct |
40 |
Correct |
101 ms |
49404 KB |
Output is correct |
41 |
Correct |
102 ms |
49452 KB |
Output is correct |
42 |
Correct |
98 ms |
49440 KB |
Output is correct |
43 |
Correct |
98 ms |
49528 KB |
Output is correct |
44 |
Correct |
101 ms |
49400 KB |
Output is correct |
45 |
Correct |
101 ms |
49532 KB |
Output is correct |
46 |
Correct |
99 ms |
49400 KB |
Output is correct |
47 |
Correct |
97 ms |
49400 KB |
Output is correct |
48 |
Correct |
830 ms |
65340 KB |
Output is correct |
49 |
Correct |
832 ms |
65012 KB |
Output is correct |
50 |
Correct |
839 ms |
65016 KB |
Output is correct |
51 |
Correct |
763 ms |
64864 KB |
Output is correct |
52 |
Correct |
715 ms |
62712 KB |
Output is correct |
53 |
Correct |
788 ms |
63412 KB |
Output is correct |
54 |
Correct |
773 ms |
61576 KB |
Output is correct |
55 |
Correct |
777 ms |
61072 KB |
Output is correct |
56 |
Correct |
768 ms |
60536 KB |
Output is correct |
57 |
Execution timed out |
2550 ms |
131796 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |