Submission #163417

# Submission time Handle Problem Language Result Execution time Memory
163417 2019-11-13T08:53:50 Z iefnah06 Rope (JOI17_rope) C++11
100 / 100
1157 ms 80760 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e6 + 10;
const int MAXM = MAXN;
int N, M;
int A[MAXN];
vector<int> v[MAXM];

int cost[MAXM];
int ind[MAXM];

int main() {
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]); A[i]--;
		v[A[i]].push_back(i);
		cost[A[i]] -= 1;
	}
	iota(ind, ind + M, 0);
	sort(ind, ind + M, [&](int a, int b) { return cost[a] < cost[b]; });

	for (int c = 0; c < M; c++) {
		int ans = N - int(v[c].size());

		for (int par = 0; par < 2; par++) {
			// at most 2 * |v[c]| incident colors
			int cnt = 0;
			for (int i : v[c]) {
				if (i > 0 && i % 2 != par) {
					cost[A[i - 1]] += 1;
					cnt++;
				}
				if (i < N - 1 && (i + 1) % 2 != par) {
					cost[A[i + 1]] += 1;
					cnt++;
				}
			}

			cnt = min(cnt + 2, M);
			int extra = N;
			for (int i = 0; i < cnt; i++) {
				if (ind[i] == c) continue;
				extra = min(extra, cost[ind[i]]);
			}
			ans = min(ans, N - int(v[c].size()) + extra);

			for (int i : v[c]) {
				if (i > 0 && i % 2 != par) {
					cost[A[i - 1]]--;
				}
				if (i < N - 1 && (i + 1) % 2 != par) {
					cost[A[i + 1]]--;
				}
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:14: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:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]); A[i]--;
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23804 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 26 ms 23852 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23876 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23804 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 24 ms 23800 KB Output is correct
20 Correct 24 ms 23800 KB Output is correct
21 Correct 23 ms 23808 KB Output is correct
22 Correct 23 ms 23804 KB Output is correct
23 Correct 23 ms 23800 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23804 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 26 ms 23852 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23876 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23804 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 24 ms 23800 KB Output is correct
20 Correct 24 ms 23800 KB Output is correct
21 Correct 23 ms 23808 KB Output is correct
22 Correct 23 ms 23804 KB Output is correct
23 Correct 23 ms 23800 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 40 ms 25132 KB Output is correct
28 Correct 38 ms 24952 KB Output is correct
29 Correct 39 ms 24952 KB Output is correct
30 Correct 38 ms 25080 KB Output is correct
31 Correct 39 ms 25036 KB Output is correct
32 Correct 38 ms 24908 KB Output is correct
33 Correct 39 ms 25208 KB Output is correct
34 Correct 39 ms 24996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23804 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 26 ms 23852 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23876 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23804 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 24 ms 23800 KB Output is correct
20 Correct 24 ms 23800 KB Output is correct
21 Correct 23 ms 23808 KB Output is correct
22 Correct 23 ms 23804 KB Output is correct
23 Correct 23 ms 23800 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 40 ms 25132 KB Output is correct
28 Correct 38 ms 24952 KB Output is correct
29 Correct 39 ms 24952 KB Output is correct
30 Correct 38 ms 25080 KB Output is correct
31 Correct 39 ms 25036 KB Output is correct
32 Correct 38 ms 24908 KB Output is correct
33 Correct 39 ms 25208 KB Output is correct
34 Correct 39 ms 24996 KB Output is correct
35 Correct 55 ms 25160 KB Output is correct
36 Correct 44 ms 25208 KB Output is correct
37 Correct 44 ms 25080 KB Output is correct
38 Correct 43 ms 25208 KB Output is correct
39 Correct 44 ms 25080 KB Output is correct
40 Correct 41 ms 25208 KB Output is correct
41 Correct 69 ms 25192 KB Output is correct
42 Correct 41 ms 25276 KB Output is correct
43 Correct 41 ms 25272 KB Output is correct
44 Correct 41 ms 25208 KB Output is correct
45 Correct 42 ms 25208 KB Output is correct
46 Correct 42 ms 25208 KB Output is correct
47 Correct 42 ms 25208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23804 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 26 ms 23852 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23876 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23804 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 24 ms 23800 KB Output is correct
20 Correct 24 ms 23800 KB Output is correct
21 Correct 23 ms 23808 KB Output is correct
22 Correct 23 ms 23804 KB Output is correct
23 Correct 23 ms 23800 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 40 ms 25132 KB Output is correct
28 Correct 38 ms 24952 KB Output is correct
29 Correct 39 ms 24952 KB Output is correct
30 Correct 38 ms 25080 KB Output is correct
31 Correct 39 ms 25036 KB Output is correct
32 Correct 38 ms 24908 KB Output is correct
33 Correct 39 ms 25208 KB Output is correct
34 Correct 39 ms 24996 KB Output is correct
35 Correct 55 ms 25160 KB Output is correct
36 Correct 44 ms 25208 KB Output is correct
37 Correct 44 ms 25080 KB Output is correct
38 Correct 43 ms 25208 KB Output is correct
39 Correct 44 ms 25080 KB Output is correct
40 Correct 41 ms 25208 KB Output is correct
41 Correct 69 ms 25192 KB Output is correct
42 Correct 41 ms 25276 KB Output is correct
43 Correct 41 ms 25272 KB Output is correct
44 Correct 41 ms 25208 KB Output is correct
45 Correct 42 ms 25208 KB Output is correct
46 Correct 42 ms 25208 KB Output is correct
47 Correct 42 ms 25208 KB Output is correct
48 Correct 318 ms 39032 KB Output is correct
49 Correct 326 ms 39052 KB Output is correct
50 Correct 307 ms 38904 KB Output is correct
51 Correct 299 ms 38676 KB Output is correct
52 Correct 296 ms 37160 KB Output is correct
53 Correct 252 ms 38076 KB Output is correct
54 Correct 234 ms 37196 KB Output is correct
55 Correct 238 ms 36984 KB Output is correct
56 Correct 249 ms 36600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23804 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 26 ms 23852 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23876 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 24 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23804 KB Output is correct
18 Correct 24 ms 23800 KB Output is correct
19 Correct 24 ms 23800 KB Output is correct
20 Correct 24 ms 23800 KB Output is correct
21 Correct 23 ms 23808 KB Output is correct
22 Correct 23 ms 23804 KB Output is correct
23 Correct 23 ms 23800 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 40 ms 25132 KB Output is correct
28 Correct 38 ms 24952 KB Output is correct
29 Correct 39 ms 24952 KB Output is correct
30 Correct 38 ms 25080 KB Output is correct
31 Correct 39 ms 25036 KB Output is correct
32 Correct 38 ms 24908 KB Output is correct
33 Correct 39 ms 25208 KB Output is correct
34 Correct 39 ms 24996 KB Output is correct
35 Correct 55 ms 25160 KB Output is correct
36 Correct 44 ms 25208 KB Output is correct
37 Correct 44 ms 25080 KB Output is correct
38 Correct 43 ms 25208 KB Output is correct
39 Correct 44 ms 25080 KB Output is correct
40 Correct 41 ms 25208 KB Output is correct
41 Correct 69 ms 25192 KB Output is correct
42 Correct 41 ms 25276 KB Output is correct
43 Correct 41 ms 25272 KB Output is correct
44 Correct 41 ms 25208 KB Output is correct
45 Correct 42 ms 25208 KB Output is correct
46 Correct 42 ms 25208 KB Output is correct
47 Correct 42 ms 25208 KB Output is correct
48 Correct 318 ms 39032 KB Output is correct
49 Correct 326 ms 39052 KB Output is correct
50 Correct 307 ms 38904 KB Output is correct
51 Correct 299 ms 38676 KB Output is correct
52 Correct 296 ms 37160 KB Output is correct
53 Correct 252 ms 38076 KB Output is correct
54 Correct 234 ms 37196 KB Output is correct
55 Correct 238 ms 36984 KB Output is correct
56 Correct 249 ms 36600 KB Output is correct
57 Correct 1157 ms 80760 KB Output is correct
58 Correct 950 ms 62232 KB Output is correct
59 Correct 897 ms 62204 KB Output is correct
60 Correct 951 ms 66864 KB Output is correct
61 Correct 967 ms 66808 KB Output is correct
62 Correct 490 ms 51192 KB Output is correct
63 Correct 663 ms 56440 KB Output is correct
64 Correct 725 ms 53424 KB Output is correct
65 Correct 363 ms 44792 KB Output is correct