Submission #849310

# Submission time Handle Problem Language Result Execution time Memory
849310 2023-09-14T12:35:40 Z 42kangaroo Rope (JOI17_rope) C++17
100 / 100
1990 ms 256872 KB
//
// Created by 42kangaroo on 11/09/2023.
//
#include "bits/stdc++.h"

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, c; cin >> n >> c;
	vector<int> colorNum(c);
	// count number of each color, and adjacent pairs of odd/even
	// put these pairs into a vec<vec<int>>
	vector<map<int,int>> adjO(c);
	vector<map<int,int>> adjE(c);
	int last = -1;
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		--a;
		colorNum[a]++;
		if (last != -1 && last != a) {
			if (i%2) {adjO[last][a]++; adjO[a][last]++;}
			else {adjE[last][a]++; adjE[a][last]++;}
		}
		last = a;
	}
	// and sort it afterwards by num
	vector<int> o(c);
	std::iota(o.begin(), o.end(),0);
	std::sort(o.begin(), o.end(), [&](int l, int r){return colorNum[l] > colorNum[r];});
	// take max of both(odd/even) for each
	vector<map<int,int>> mins(c);
	for (int i = 0; i < c; ++i) {
		for (auto [k, v]: adjE[i]) {
			if (adjO[i].find(k) != adjO[i].end()) {
				mins[i][k] = min(adjO[i][k], adjE[i][k]);
			}
		}
	}
	// go down with a pointer in the sorted list and check those with connection the max without
	for (int i = 0; i < c; ++i) {
		int mi = n - colorNum[i];
		int j = 0;
		if (j < c && o[j] == i) j++;
		for (; j < c && mins[i].find(o[j]) != mins[i].end(); ++j) {
			mi = min(n - colorNum[i] - colorNum[o[j]] + mins[i][o[j]], mi);
			if (j < c - 1 && o[j + 1] == i) ++j;
		}
		if (j < c) {
			mi = min(n - colorNum[i] - colorNum[o[j]], mi);
		}
		cout << mi<< "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 6 ms 600 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 6 ms 600 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 59 ms 9816 KB Output is correct
36 Correct 55 ms 9836 KB Output is correct
37 Correct 72 ms 10068 KB Output is correct
38 Correct 58 ms 9808 KB Output is correct
39 Correct 55 ms 9720 KB Output is correct
40 Correct 29 ms 5604 KB Output is correct
41 Correct 28 ms 5724 KB Output is correct
42 Correct 24 ms 4852 KB Output is correct
43 Correct 25 ms 4792 KB Output is correct
44 Correct 28 ms 5724 KB Output is correct
45 Correct 28 ms 5716 KB Output is correct
46 Correct 25 ms 4948 KB Output is correct
47 Correct 25 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 6 ms 600 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 59 ms 9816 KB Output is correct
36 Correct 55 ms 9836 KB Output is correct
37 Correct 72 ms 10068 KB Output is correct
38 Correct 58 ms 9808 KB Output is correct
39 Correct 55 ms 9720 KB Output is correct
40 Correct 29 ms 5604 KB Output is correct
41 Correct 28 ms 5724 KB Output is correct
42 Correct 24 ms 4852 KB Output is correct
43 Correct 25 ms 4792 KB Output is correct
44 Correct 28 ms 5724 KB Output is correct
45 Correct 28 ms 5716 KB Output is correct
46 Correct 25 ms 4948 KB Output is correct
47 Correct 25 ms 4948 KB Output is correct
48 Correct 1839 ms 99008 KB Output is correct
49 Correct 1955 ms 98844 KB Output is correct
50 Correct 1853 ms 98996 KB Output is correct
51 Correct 1990 ms 93984 KB Output is correct
52 Correct 1701 ms 82376 KB Output is correct
53 Correct 671 ms 61400 KB Output is correct
54 Correct 428 ms 50152 KB Output is correct
55 Correct 424 ms 49232 KB Output is correct
56 Correct 383 ms 44696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 6 ms 600 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 5 ms 604 KB Output is correct
33 Correct 6 ms 604 KB Output is correct
34 Correct 6 ms 604 KB Output is correct
35 Correct 59 ms 9816 KB Output is correct
36 Correct 55 ms 9836 KB Output is correct
37 Correct 72 ms 10068 KB Output is correct
38 Correct 58 ms 9808 KB Output is correct
39 Correct 55 ms 9720 KB Output is correct
40 Correct 29 ms 5604 KB Output is correct
41 Correct 28 ms 5724 KB Output is correct
42 Correct 24 ms 4852 KB Output is correct
43 Correct 25 ms 4792 KB Output is correct
44 Correct 28 ms 5724 KB Output is correct
45 Correct 28 ms 5716 KB Output is correct
46 Correct 25 ms 4948 KB Output is correct
47 Correct 25 ms 4948 KB Output is correct
48 Correct 1839 ms 99008 KB Output is correct
49 Correct 1955 ms 98844 KB Output is correct
50 Correct 1853 ms 98996 KB Output is correct
51 Correct 1990 ms 93984 KB Output is correct
52 Correct 1701 ms 82376 KB Output is correct
53 Correct 671 ms 61400 KB Output is correct
54 Correct 428 ms 50152 KB Output is correct
55 Correct 424 ms 49232 KB Output is correct
56 Correct 383 ms 44696 KB Output is correct
57 Correct 732 ms 256872 KB Output is correct
58 Correct 807 ms 194388 KB Output is correct
59 Correct 840 ms 193988 KB Output is correct
60 Correct 790 ms 209964 KB Output is correct
61 Correct 784 ms 210096 KB Output is correct
62 Correct 487 ms 108884 KB Output is correct
63 Correct 568 ms 142776 KB Output is correct
64 Correct 540 ms 124004 KB Output is correct
65 Correct 421 ms 76632 KB Output is correct