답안 #614119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614119 2022-07-30T19:14:44 Z valerikk Rope (JOI17_rope) C++17
55 / 100
2500 ms 74464 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> c(n);
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		--c[i];
	}
	vector<int> cnt(m, 0);
	for (int i = 0; i < n; ++i) {
		++cnt[c[i]];
	}
	vector<int> ans(m);
	for (int u = 0; u < m; ++u) {
		ans[u] = n - cnt[u];
	}
	for (int p = 0; p < 2; ++p) {
		map<pair<int, int>, int> mp;
		vector<vector<int>> g(m);
		for (int i = p; i + 1 < n; i += 2) {
			if (c[i] != c[i + 1]) {
				++mp[{c[i], c[i + 1]}];
				++mp[{c[i + 1], c[i]}];
				g[c[i]].push_back(c[i + 1]);
				g[c[i + 1]].push_back(c[i]);
			}
		}
		set<pair<int, int>> s;
		for (int u = 0; u < m; ++u) {
			s.insert({cnt[u], u});
		}
		for (int u = 0; u < m; ++u) {
			sort(begin(g[u]), end(g[u]));
			g[u].resize(unique(begin(g[u]), end(g[u])) - begin(g[u]));
			for (int v : g[u]) {
				ans[u] = min(ans[u], n - cnt[u] - cnt[v] + mp[{u, v}]);
			}
			for (int v : g[u]) {
				s.erase({cnt[v], v});
			}
			s.erase({cnt[u], u});
			ans[u] = min(ans[u], n - cnt[u] - (s.empty() ? 0 : s.rbegin()->first));
			s.insert({cnt[u], u});
			for (int v : g[u]) {
				s.insert({cnt[v], v});
			}
		}
	}
	for (int u = 0; u < m; ++u) {
		cout << ans[u] << "\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 18 ms 1608 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
29 Correct 17 ms 1492 KB Output is correct
30 Correct 16 ms 1320 KB Output is correct
31 Correct 16 ms 1536 KB Output is correct
32 Correct 12 ms 1456 KB Output is correct
33 Correct 16 ms 1492 KB Output is correct
34 Correct 13 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 18 ms 1608 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
29 Correct 17 ms 1492 KB Output is correct
30 Correct 16 ms 1320 KB Output is correct
31 Correct 16 ms 1536 KB Output is correct
32 Correct 12 ms 1456 KB Output is correct
33 Correct 16 ms 1492 KB Output is correct
34 Correct 13 ms 1388 KB Output is correct
35 Correct 154 ms 6944 KB Output is correct
36 Correct 131 ms 6780 KB Output is correct
37 Correct 130 ms 6720 KB Output is correct
38 Correct 138 ms 6768 KB Output is correct
39 Correct 145 ms 6860 KB Output is correct
40 Correct 75 ms 4424 KB Output is correct
41 Correct 81 ms 4484 KB Output is correct
42 Correct 62 ms 3856 KB Output is correct
43 Correct 64 ms 3748 KB Output is correct
44 Correct 85 ms 4500 KB Output is correct
45 Correct 81 ms 4556 KB Output is correct
46 Correct 74 ms 3788 KB Output is correct
47 Correct 68 ms 3780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 18 ms 1608 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
29 Correct 17 ms 1492 KB Output is correct
30 Correct 16 ms 1320 KB Output is correct
31 Correct 16 ms 1536 KB Output is correct
32 Correct 12 ms 1456 KB Output is correct
33 Correct 16 ms 1492 KB Output is correct
34 Correct 13 ms 1388 KB Output is correct
35 Correct 154 ms 6944 KB Output is correct
36 Correct 131 ms 6780 KB Output is correct
37 Correct 130 ms 6720 KB Output is correct
38 Correct 138 ms 6768 KB Output is correct
39 Correct 145 ms 6860 KB Output is correct
40 Correct 75 ms 4424 KB Output is correct
41 Correct 81 ms 4484 KB Output is correct
42 Correct 62 ms 3856 KB Output is correct
43 Correct 64 ms 3748 KB Output is correct
44 Correct 85 ms 4500 KB Output is correct
45 Correct 81 ms 4556 KB Output is correct
46 Correct 74 ms 3788 KB Output is correct
47 Correct 68 ms 3780 KB Output is correct
48 Execution timed out 2568 ms 74464 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 316 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 18 ms 1608 KB Output is correct
28 Correct 12 ms 1436 KB Output is correct
29 Correct 17 ms 1492 KB Output is correct
30 Correct 16 ms 1320 KB Output is correct
31 Correct 16 ms 1536 KB Output is correct
32 Correct 12 ms 1456 KB Output is correct
33 Correct 16 ms 1492 KB Output is correct
34 Correct 13 ms 1388 KB Output is correct
35 Correct 154 ms 6944 KB Output is correct
36 Correct 131 ms 6780 KB Output is correct
37 Correct 130 ms 6720 KB Output is correct
38 Correct 138 ms 6768 KB Output is correct
39 Correct 145 ms 6860 KB Output is correct
40 Correct 75 ms 4424 KB Output is correct
41 Correct 81 ms 4484 KB Output is correct
42 Correct 62 ms 3856 KB Output is correct
43 Correct 64 ms 3748 KB Output is correct
44 Correct 85 ms 4500 KB Output is correct
45 Correct 81 ms 4556 KB Output is correct
46 Correct 74 ms 3788 KB Output is correct
47 Correct 68 ms 3780 KB Output is correct
48 Execution timed out 2568 ms 74464 KB Time limit exceeded
49 Halted 0 ms 0 KB -