답안 #534498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534498 2022-03-08T08:12:37 Z rk42745417 Rope (JOI17_rope) C++17
55 / 100
2500 ms 53548 KB
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
static int Lamy_is_cute = []() {
	EmiliaMyWife
	return 48763;
}();
/*--------------------------------------------------------------------------------------*/

signed main() {
	int n, m;
	cin >> n >> m;
	vector<int> arr(n);
	for(int &a : arr)
		cin >> a;
	vector<int> ans(m + 1, INF);
	for(int st : {1, 2}) {
		vector<int> cnt(m + 1);
		vector<map<int, int>> adj(m + 1);
		for(int i = 0; i < n; i++)
			cnt[arr[i]]++;
		for(int i = st; i < n; i += 2) {
			int a = arr[i - 1], b = arr[i];
			if(a != b) {
				adj[a][b]++;
				adj[b][a]++;
			}
		}

		multiset<int> has;
		for(int i = 1; i <= m; i++)
			has.insert(cnt[i]);
		has.insert(0);

		for(int i = 1; i <= m; i++) {
			int res = 0;
			has.erase(has.lower_bound(cnt[i]));
			for(const auto &[a, c] : adj[i]) {
				res = max(res, cnt[a] - c);
				has.erase(has.lower_bound(cnt[a]));
			}
			res = max(res, *has.rbegin());
			ans[i] = min(ans[i], n - (res + cnt[i]));
			
			has.insert(cnt[i]);
			for(const auto &[a, _] : adj[i])
				has.insert(cnt[a]);
		}
	}
	for(int i = 1; i <= m; i++)
		cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 10 ms 908 KB Output is correct
28 Correct 7 ms 844 KB Output is correct
29 Correct 11 ms 828 KB Output is correct
30 Correct 9 ms 844 KB Output is correct
31 Correct 11 ms 836 KB Output is correct
32 Correct 8 ms 844 KB Output is correct
33 Correct 10 ms 844 KB Output is correct
34 Correct 9 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 10 ms 908 KB Output is correct
28 Correct 7 ms 844 KB Output is correct
29 Correct 11 ms 828 KB Output is correct
30 Correct 9 ms 844 KB Output is correct
31 Correct 11 ms 836 KB Output is correct
32 Correct 8 ms 844 KB Output is correct
33 Correct 10 ms 844 KB Output is correct
34 Correct 9 ms 844 KB Output is correct
35 Correct 104 ms 4988 KB Output is correct
36 Correct 104 ms 4984 KB Output is correct
37 Correct 113 ms 4932 KB Output is correct
38 Correct 80 ms 4932 KB Output is correct
39 Correct 118 ms 4908 KB Output is correct
40 Correct 44 ms 3140 KB Output is correct
41 Correct 43 ms 3136 KB Output is correct
42 Correct 35 ms 2684 KB Output is correct
43 Correct 39 ms 2600 KB Output is correct
44 Correct 50 ms 3168 KB Output is correct
45 Correct 56 ms 3184 KB Output is correct
46 Correct 38 ms 2732 KB Output is correct
47 Correct 35 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 10 ms 908 KB Output is correct
28 Correct 7 ms 844 KB Output is correct
29 Correct 11 ms 828 KB Output is correct
30 Correct 9 ms 844 KB Output is correct
31 Correct 11 ms 836 KB Output is correct
32 Correct 8 ms 844 KB Output is correct
33 Correct 10 ms 844 KB Output is correct
34 Correct 9 ms 844 KB Output is correct
35 Correct 104 ms 4988 KB Output is correct
36 Correct 104 ms 4984 KB Output is correct
37 Correct 113 ms 4932 KB Output is correct
38 Correct 80 ms 4932 KB Output is correct
39 Correct 118 ms 4908 KB Output is correct
40 Correct 44 ms 3140 KB Output is correct
41 Correct 43 ms 3136 KB Output is correct
42 Correct 35 ms 2684 KB Output is correct
43 Correct 39 ms 2600 KB Output is correct
44 Correct 50 ms 3168 KB Output is correct
45 Correct 56 ms 3184 KB Output is correct
46 Correct 38 ms 2732 KB Output is correct
47 Correct 35 ms 2624 KB Output is correct
48 Execution timed out 2517 ms 53548 KB Time limit exceeded
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 10 ms 908 KB Output is correct
28 Correct 7 ms 844 KB Output is correct
29 Correct 11 ms 828 KB Output is correct
30 Correct 9 ms 844 KB Output is correct
31 Correct 11 ms 836 KB Output is correct
32 Correct 8 ms 844 KB Output is correct
33 Correct 10 ms 844 KB Output is correct
34 Correct 9 ms 844 KB Output is correct
35 Correct 104 ms 4988 KB Output is correct
36 Correct 104 ms 4984 KB Output is correct
37 Correct 113 ms 4932 KB Output is correct
38 Correct 80 ms 4932 KB Output is correct
39 Correct 118 ms 4908 KB Output is correct
40 Correct 44 ms 3140 KB Output is correct
41 Correct 43 ms 3136 KB Output is correct
42 Correct 35 ms 2684 KB Output is correct
43 Correct 39 ms 2600 KB Output is correct
44 Correct 50 ms 3168 KB Output is correct
45 Correct 56 ms 3184 KB Output is correct
46 Correct 38 ms 2732 KB Output is correct
47 Correct 35 ms 2624 KB Output is correct
48 Execution timed out 2517 ms 53548 KB Time limit exceeded
49 Halted 0 ms 0 KB -