# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
128510 |
2019-07-11T04:46:16 Z |
임유진(#3161) |
Rope (JOI17_rope) |
C++14 |
|
1076 ms |
132876 KB |
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
#define MAXN 1000005
#define MAXM 1000005
typedef pair<int, int> pii;
int C[MAXN];
int A[MAXM];
pii as[MAXN];
vector<int> cha[MAXM][2];
int main() {
int N, M;
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i++) scanf("%d", C + i);
for(int i = 0; i < N; i++) A[C[i]]++;
for(int i = 0; i < N - 1; i++) if(C[i] != C[i + 1]) {
cha[C[i]][i % 2].push_back(C[i + 1]);
cha[C[i + 1]][i % 2].push_back(C[i]);
}
for(int i = 1; i <= M; i++) {
sort(cha[i][0].begin(), cha[i][0].end());
sort(cha[i][1].begin(), cha[i][1].end());
}
for(int i = 1; i <= M; i++) as[i - 1] = make_pair(A[i], i);
sort(as, as + M, greater<pii>());
//for(int i = 0; i < M; i++) printf("(%d, %d)", as[i].first, as[i].second);
for(int i = 1; i <= M; i++) {
int mn = N - A[i];
for(int j = 0; j < M; j++) if(as[j].second != i) {
if(!binary_search(cha[i][0].begin(), cha[i][0].end(), as[j].second) && !binary_search(cha[i][1].begin(), cha[i][1].end(), as[j].second)) {
//printf("i = %d, as[j] = (%d, %d)\n", i, as[j].first, as[j].second);
mn = min(mn, N - A[i] - as[j].first);
break;
}
}
for(auto a : cha[i][0]) {
//printf("i = %d, a = %d\n", i, a);
int cnt0 = upper_bound(cha[i][0].begin(), cha[i][0].end(), a) - lower_bound(cha[i][0].begin(), cha[i][0].end(), a);
int cnt1 = upper_bound(cha[i][1].begin(), cha[i][1].end(), a) - lower_bound(cha[i][1].begin(), cha[i][1].end(), a);
mn = min(mn, N - A[i] - A[a] + min(cnt0, cnt1));
}
for(auto a : cha[i][1]) {
//printf("i = %d, a = %d\n", i, a);
int cnt0 = upper_bound(cha[i][0].begin(), cha[i][0].end(), a) - lower_bound(cha[i][0].begin(), cha[i][0].end(), a);
int cnt1 = upper_bound(cha[i][1].begin(), cha[i][1].end(), a) - lower_bound(cha[i][1].begin(), cha[i][1].end(), a);
mn = min(mn, N - A[i] - A[a] + min(cnt0, cnt1));
}
printf("%d\n", mn);
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
rope.cpp:22:34: 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", C + i);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47224 KB |
Output is correct |
2 |
Correct |
44 ms |
47224 KB |
Output is correct |
3 |
Correct |
45 ms |
47216 KB |
Output is correct |
4 |
Correct |
45 ms |
47352 KB |
Output is correct |
5 |
Correct |
45 ms |
47340 KB |
Output is correct |
6 |
Correct |
45 ms |
47324 KB |
Output is correct |
7 |
Correct |
44 ms |
47224 KB |
Output is correct |
8 |
Correct |
44 ms |
47352 KB |
Output is correct |
9 |
Correct |
44 ms |
47224 KB |
Output is correct |
10 |
Correct |
45 ms |
47352 KB |
Output is correct |
11 |
Correct |
45 ms |
47376 KB |
Output is correct |
12 |
Correct |
45 ms |
47232 KB |
Output is correct |
13 |
Correct |
44 ms |
47476 KB |
Output is correct |
14 |
Correct |
45 ms |
47352 KB |
Output is correct |
15 |
Correct |
54 ms |
47324 KB |
Output is correct |
16 |
Correct |
45 ms |
47224 KB |
Output is correct |
17 |
Correct |
44 ms |
47224 KB |
Output is correct |
18 |
Correct |
44 ms |
47224 KB |
Output is correct |
19 |
Correct |
45 ms |
47276 KB |
Output is correct |
20 |
Correct |
44 ms |
47352 KB |
Output is correct |
21 |
Correct |
46 ms |
47224 KB |
Output is correct |
22 |
Correct |
45 ms |
47352 KB |
Output is correct |
23 |
Correct |
45 ms |
47352 KB |
Output is correct |
24 |
Correct |
45 ms |
47352 KB |
Output is correct |
25 |
Correct |
45 ms |
47352 KB |
Output is correct |
26 |
Correct |
44 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47224 KB |
Output is correct |
2 |
Correct |
44 ms |
47224 KB |
Output is correct |
3 |
Correct |
45 ms |
47216 KB |
Output is correct |
4 |
Correct |
45 ms |
47352 KB |
Output is correct |
5 |
Correct |
45 ms |
47340 KB |
Output is correct |
6 |
Correct |
45 ms |
47324 KB |
Output is correct |
7 |
Correct |
44 ms |
47224 KB |
Output is correct |
8 |
Correct |
44 ms |
47352 KB |
Output is correct |
9 |
Correct |
44 ms |
47224 KB |
Output is correct |
10 |
Correct |
45 ms |
47352 KB |
Output is correct |
11 |
Correct |
45 ms |
47376 KB |
Output is correct |
12 |
Correct |
45 ms |
47232 KB |
Output is correct |
13 |
Correct |
44 ms |
47476 KB |
Output is correct |
14 |
Correct |
45 ms |
47352 KB |
Output is correct |
15 |
Correct |
54 ms |
47324 KB |
Output is correct |
16 |
Correct |
45 ms |
47224 KB |
Output is correct |
17 |
Correct |
44 ms |
47224 KB |
Output is correct |
18 |
Correct |
44 ms |
47224 KB |
Output is correct |
19 |
Correct |
45 ms |
47276 KB |
Output is correct |
20 |
Correct |
44 ms |
47352 KB |
Output is correct |
21 |
Correct |
46 ms |
47224 KB |
Output is correct |
22 |
Correct |
45 ms |
47352 KB |
Output is correct |
23 |
Correct |
45 ms |
47352 KB |
Output is correct |
24 |
Correct |
45 ms |
47352 KB |
Output is correct |
25 |
Correct |
45 ms |
47352 KB |
Output is correct |
26 |
Correct |
44 ms |
47352 KB |
Output is correct |
27 |
Correct |
82 ms |
48764 KB |
Output is correct |
28 |
Correct |
71 ms |
48760 KB |
Output is correct |
29 |
Correct |
77 ms |
48760 KB |
Output is correct |
30 |
Correct |
73 ms |
48504 KB |
Output is correct |
31 |
Correct |
77 ms |
48848 KB |
Output is correct |
32 |
Correct |
72 ms |
48680 KB |
Output is correct |
33 |
Correct |
76 ms |
48760 KB |
Output is correct |
34 |
Correct |
72 ms |
48376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47224 KB |
Output is correct |
2 |
Correct |
44 ms |
47224 KB |
Output is correct |
3 |
Correct |
45 ms |
47216 KB |
Output is correct |
4 |
Correct |
45 ms |
47352 KB |
Output is correct |
5 |
Correct |
45 ms |
47340 KB |
Output is correct |
6 |
Correct |
45 ms |
47324 KB |
Output is correct |
7 |
Correct |
44 ms |
47224 KB |
Output is correct |
8 |
Correct |
44 ms |
47352 KB |
Output is correct |
9 |
Correct |
44 ms |
47224 KB |
Output is correct |
10 |
Correct |
45 ms |
47352 KB |
Output is correct |
11 |
Correct |
45 ms |
47376 KB |
Output is correct |
12 |
Correct |
45 ms |
47232 KB |
Output is correct |
13 |
Correct |
44 ms |
47476 KB |
Output is correct |
14 |
Correct |
45 ms |
47352 KB |
Output is correct |
15 |
Correct |
54 ms |
47324 KB |
Output is correct |
16 |
Correct |
45 ms |
47224 KB |
Output is correct |
17 |
Correct |
44 ms |
47224 KB |
Output is correct |
18 |
Correct |
44 ms |
47224 KB |
Output is correct |
19 |
Correct |
45 ms |
47276 KB |
Output is correct |
20 |
Correct |
44 ms |
47352 KB |
Output is correct |
21 |
Correct |
46 ms |
47224 KB |
Output is correct |
22 |
Correct |
45 ms |
47352 KB |
Output is correct |
23 |
Correct |
45 ms |
47352 KB |
Output is correct |
24 |
Correct |
45 ms |
47352 KB |
Output is correct |
25 |
Correct |
45 ms |
47352 KB |
Output is correct |
26 |
Correct |
44 ms |
47352 KB |
Output is correct |
27 |
Correct |
82 ms |
48764 KB |
Output is correct |
28 |
Correct |
71 ms |
48760 KB |
Output is correct |
29 |
Correct |
77 ms |
48760 KB |
Output is correct |
30 |
Correct |
73 ms |
48504 KB |
Output is correct |
31 |
Correct |
77 ms |
48848 KB |
Output is correct |
32 |
Correct |
72 ms |
48680 KB |
Output is correct |
33 |
Correct |
76 ms |
48760 KB |
Output is correct |
34 |
Correct |
72 ms |
48376 KB |
Output is correct |
35 |
Correct |
103 ms |
48768 KB |
Output is correct |
36 |
Correct |
103 ms |
48760 KB |
Output is correct |
37 |
Correct |
104 ms |
48760 KB |
Output is correct |
38 |
Correct |
103 ms |
48760 KB |
Output is correct |
39 |
Correct |
104 ms |
48860 KB |
Output is correct |
40 |
Correct |
95 ms |
49016 KB |
Output is correct |
41 |
Correct |
96 ms |
49016 KB |
Output is correct |
42 |
Correct |
98 ms |
49016 KB |
Output is correct |
43 |
Correct |
96 ms |
49144 KB |
Output is correct |
44 |
Correct |
95 ms |
48888 KB |
Output is correct |
45 |
Correct |
96 ms |
49016 KB |
Output is correct |
46 |
Correct |
94 ms |
48888 KB |
Output is correct |
47 |
Correct |
95 ms |
48888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47224 KB |
Output is correct |
2 |
Correct |
44 ms |
47224 KB |
Output is correct |
3 |
Correct |
45 ms |
47216 KB |
Output is correct |
4 |
Correct |
45 ms |
47352 KB |
Output is correct |
5 |
Correct |
45 ms |
47340 KB |
Output is correct |
6 |
Correct |
45 ms |
47324 KB |
Output is correct |
7 |
Correct |
44 ms |
47224 KB |
Output is correct |
8 |
Correct |
44 ms |
47352 KB |
Output is correct |
9 |
Correct |
44 ms |
47224 KB |
Output is correct |
10 |
Correct |
45 ms |
47352 KB |
Output is correct |
11 |
Correct |
45 ms |
47376 KB |
Output is correct |
12 |
Correct |
45 ms |
47232 KB |
Output is correct |
13 |
Correct |
44 ms |
47476 KB |
Output is correct |
14 |
Correct |
45 ms |
47352 KB |
Output is correct |
15 |
Correct |
54 ms |
47324 KB |
Output is correct |
16 |
Correct |
45 ms |
47224 KB |
Output is correct |
17 |
Correct |
44 ms |
47224 KB |
Output is correct |
18 |
Correct |
44 ms |
47224 KB |
Output is correct |
19 |
Correct |
45 ms |
47276 KB |
Output is correct |
20 |
Correct |
44 ms |
47352 KB |
Output is correct |
21 |
Correct |
46 ms |
47224 KB |
Output is correct |
22 |
Correct |
45 ms |
47352 KB |
Output is correct |
23 |
Correct |
45 ms |
47352 KB |
Output is correct |
24 |
Correct |
45 ms |
47352 KB |
Output is correct |
25 |
Correct |
45 ms |
47352 KB |
Output is correct |
26 |
Correct |
44 ms |
47352 KB |
Output is correct |
27 |
Correct |
82 ms |
48764 KB |
Output is correct |
28 |
Correct |
71 ms |
48760 KB |
Output is correct |
29 |
Correct |
77 ms |
48760 KB |
Output is correct |
30 |
Correct |
73 ms |
48504 KB |
Output is correct |
31 |
Correct |
77 ms |
48848 KB |
Output is correct |
32 |
Correct |
72 ms |
48680 KB |
Output is correct |
33 |
Correct |
76 ms |
48760 KB |
Output is correct |
34 |
Correct |
72 ms |
48376 KB |
Output is correct |
35 |
Correct |
103 ms |
48768 KB |
Output is correct |
36 |
Correct |
103 ms |
48760 KB |
Output is correct |
37 |
Correct |
104 ms |
48760 KB |
Output is correct |
38 |
Correct |
103 ms |
48760 KB |
Output is correct |
39 |
Correct |
104 ms |
48860 KB |
Output is correct |
40 |
Correct |
95 ms |
49016 KB |
Output is correct |
41 |
Correct |
96 ms |
49016 KB |
Output is correct |
42 |
Correct |
98 ms |
49016 KB |
Output is correct |
43 |
Correct |
96 ms |
49144 KB |
Output is correct |
44 |
Correct |
95 ms |
48888 KB |
Output is correct |
45 |
Correct |
96 ms |
49016 KB |
Output is correct |
46 |
Correct |
94 ms |
48888 KB |
Output is correct |
47 |
Correct |
95 ms |
48888 KB |
Output is correct |
48 |
Correct |
715 ms |
64452 KB |
Output is correct |
49 |
Correct |
706 ms |
64504 KB |
Output is correct |
50 |
Correct |
707 ms |
64632 KB |
Output is correct |
51 |
Correct |
697 ms |
64388 KB |
Output is correct |
52 |
Correct |
683 ms |
62328 KB |
Output is correct |
53 |
Correct |
626 ms |
62844 KB |
Output is correct |
54 |
Correct |
612 ms |
60968 KB |
Output is correct |
55 |
Correct |
611 ms |
60636 KB |
Output is correct |
56 |
Correct |
602 ms |
59896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47224 KB |
Output is correct |
2 |
Correct |
44 ms |
47224 KB |
Output is correct |
3 |
Correct |
45 ms |
47216 KB |
Output is correct |
4 |
Correct |
45 ms |
47352 KB |
Output is correct |
5 |
Correct |
45 ms |
47340 KB |
Output is correct |
6 |
Correct |
45 ms |
47324 KB |
Output is correct |
7 |
Correct |
44 ms |
47224 KB |
Output is correct |
8 |
Correct |
44 ms |
47352 KB |
Output is correct |
9 |
Correct |
44 ms |
47224 KB |
Output is correct |
10 |
Correct |
45 ms |
47352 KB |
Output is correct |
11 |
Correct |
45 ms |
47376 KB |
Output is correct |
12 |
Correct |
45 ms |
47232 KB |
Output is correct |
13 |
Correct |
44 ms |
47476 KB |
Output is correct |
14 |
Correct |
45 ms |
47352 KB |
Output is correct |
15 |
Correct |
54 ms |
47324 KB |
Output is correct |
16 |
Correct |
45 ms |
47224 KB |
Output is correct |
17 |
Correct |
44 ms |
47224 KB |
Output is correct |
18 |
Correct |
44 ms |
47224 KB |
Output is correct |
19 |
Correct |
45 ms |
47276 KB |
Output is correct |
20 |
Correct |
44 ms |
47352 KB |
Output is correct |
21 |
Correct |
46 ms |
47224 KB |
Output is correct |
22 |
Correct |
45 ms |
47352 KB |
Output is correct |
23 |
Correct |
45 ms |
47352 KB |
Output is correct |
24 |
Correct |
45 ms |
47352 KB |
Output is correct |
25 |
Correct |
45 ms |
47352 KB |
Output is correct |
26 |
Correct |
44 ms |
47352 KB |
Output is correct |
27 |
Correct |
82 ms |
48764 KB |
Output is correct |
28 |
Correct |
71 ms |
48760 KB |
Output is correct |
29 |
Correct |
77 ms |
48760 KB |
Output is correct |
30 |
Correct |
73 ms |
48504 KB |
Output is correct |
31 |
Correct |
77 ms |
48848 KB |
Output is correct |
32 |
Correct |
72 ms |
48680 KB |
Output is correct |
33 |
Correct |
76 ms |
48760 KB |
Output is correct |
34 |
Correct |
72 ms |
48376 KB |
Output is correct |
35 |
Correct |
103 ms |
48768 KB |
Output is correct |
36 |
Correct |
103 ms |
48760 KB |
Output is correct |
37 |
Correct |
104 ms |
48760 KB |
Output is correct |
38 |
Correct |
103 ms |
48760 KB |
Output is correct |
39 |
Correct |
104 ms |
48860 KB |
Output is correct |
40 |
Correct |
95 ms |
49016 KB |
Output is correct |
41 |
Correct |
96 ms |
49016 KB |
Output is correct |
42 |
Correct |
98 ms |
49016 KB |
Output is correct |
43 |
Correct |
96 ms |
49144 KB |
Output is correct |
44 |
Correct |
95 ms |
48888 KB |
Output is correct |
45 |
Correct |
96 ms |
49016 KB |
Output is correct |
46 |
Correct |
94 ms |
48888 KB |
Output is correct |
47 |
Correct |
95 ms |
48888 KB |
Output is correct |
48 |
Correct |
715 ms |
64452 KB |
Output is correct |
49 |
Correct |
706 ms |
64504 KB |
Output is correct |
50 |
Correct |
707 ms |
64632 KB |
Output is correct |
51 |
Correct |
697 ms |
64388 KB |
Output is correct |
52 |
Correct |
683 ms |
62328 KB |
Output is correct |
53 |
Correct |
626 ms |
62844 KB |
Output is correct |
54 |
Correct |
612 ms |
60968 KB |
Output is correct |
55 |
Correct |
611 ms |
60636 KB |
Output is correct |
56 |
Correct |
602 ms |
59896 KB |
Output is correct |
57 |
Correct |
1026 ms |
132876 KB |
Output is correct |
58 |
Correct |
1016 ms |
101312 KB |
Output is correct |
59 |
Correct |
1035 ms |
101112 KB |
Output is correct |
60 |
Correct |
1060 ms |
109168 KB |
Output is correct |
61 |
Correct |
1076 ms |
109336 KB |
Output is correct |
62 |
Correct |
799 ms |
83012 KB |
Output is correct |
63 |
Correct |
959 ms |
91512 KB |
Output is correct |
64 |
Correct |
944 ms |
86308 KB |
Output is correct |
65 |
Correct |
680 ms |
72456 KB |
Output is correct |