/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
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);
vector<pair<int, int>> cnt(m + 1);
vector<int> owo(m + 1);
for(int i = 1; i <= m; i++)
cnt[i].second = i;
for(int a : arr)
cnt[a].first++, owo[a]++;
sort(cnt.begin(), cnt.end(), greater<>());
for(int st : {1, 2}) {
vector<map<int, int>> adj(m + 1);
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]++;
}
}
for(int i = 1; i <= m; i++) {
int res = 0;
for(const auto &[c, j] : cnt) {
if(j == i)
continue;
res = max(res, c - adj[i][j]);
if(adj[i][j] == 0)
break;
}
ans[i] = min(ans[i], n - (res + owo[i]));
}
}
for(int i = 1; i <= m; i++)
cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
11 ms |
716 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
9 ms |
588 KB |
Output is correct |
30 |
Correct |
11 ms |
588 KB |
Output is correct |
31 |
Correct |
11 ms |
712 KB |
Output is correct |
32 |
Correct |
7 ms |
716 KB |
Output is correct |
33 |
Correct |
10 ms |
588 KB |
Output is correct |
34 |
Correct |
11 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
11 ms |
716 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
9 ms |
588 KB |
Output is correct |
30 |
Correct |
11 ms |
588 KB |
Output is correct |
31 |
Correct |
11 ms |
712 KB |
Output is correct |
32 |
Correct |
7 ms |
716 KB |
Output is correct |
33 |
Correct |
10 ms |
588 KB |
Output is correct |
34 |
Correct |
11 ms |
588 KB |
Output is correct |
35 |
Correct |
47 ms |
4556 KB |
Output is correct |
36 |
Correct |
47 ms |
4544 KB |
Output is correct |
37 |
Correct |
51 ms |
4436 KB |
Output is correct |
38 |
Correct |
62 ms |
4664 KB |
Output is correct |
39 |
Correct |
68 ms |
4600 KB |
Output is correct |
40 |
Correct |
28 ms |
2892 KB |
Output is correct |
41 |
Correct |
27 ms |
2772 KB |
Output is correct |
42 |
Correct |
25 ms |
2252 KB |
Output is correct |
43 |
Correct |
24 ms |
2256 KB |
Output is correct |
44 |
Correct |
28 ms |
2776 KB |
Output is correct |
45 |
Correct |
27 ms |
2760 KB |
Output is correct |
46 |
Correct |
23 ms |
2252 KB |
Output is correct |
47 |
Correct |
26 ms |
2276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
11 ms |
716 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
9 ms |
588 KB |
Output is correct |
30 |
Correct |
11 ms |
588 KB |
Output is correct |
31 |
Correct |
11 ms |
712 KB |
Output is correct |
32 |
Correct |
7 ms |
716 KB |
Output is correct |
33 |
Correct |
10 ms |
588 KB |
Output is correct |
34 |
Correct |
11 ms |
588 KB |
Output is correct |
35 |
Correct |
47 ms |
4556 KB |
Output is correct |
36 |
Correct |
47 ms |
4544 KB |
Output is correct |
37 |
Correct |
51 ms |
4436 KB |
Output is correct |
38 |
Correct |
62 ms |
4664 KB |
Output is correct |
39 |
Correct |
68 ms |
4600 KB |
Output is correct |
40 |
Correct |
28 ms |
2892 KB |
Output is correct |
41 |
Correct |
27 ms |
2772 KB |
Output is correct |
42 |
Correct |
25 ms |
2252 KB |
Output is correct |
43 |
Correct |
24 ms |
2256 KB |
Output is correct |
44 |
Correct |
28 ms |
2776 KB |
Output is correct |
45 |
Correct |
27 ms |
2760 KB |
Output is correct |
46 |
Correct |
23 ms |
2252 KB |
Output is correct |
47 |
Correct |
26 ms |
2276 KB |
Output is correct |
48 |
Correct |
1764 ms |
49080 KB |
Output is correct |
49 |
Correct |
1654 ms |
53632 KB |
Output is correct |
50 |
Correct |
1675 ms |
53716 KB |
Output is correct |
51 |
Correct |
1595 ms |
46412 KB |
Output is correct |
52 |
Correct |
1366 ms |
37772 KB |
Output is correct |
53 |
Correct |
614 ms |
32868 KB |
Output is correct |
54 |
Correct |
429 ms |
26404 KB |
Output is correct |
55 |
Correct |
436 ms |
25960 KB |
Output is correct |
56 |
Correct |
451 ms |
23208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
11 ms |
716 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
9 ms |
588 KB |
Output is correct |
30 |
Correct |
11 ms |
588 KB |
Output is correct |
31 |
Correct |
11 ms |
712 KB |
Output is correct |
32 |
Correct |
7 ms |
716 KB |
Output is correct |
33 |
Correct |
10 ms |
588 KB |
Output is correct |
34 |
Correct |
11 ms |
588 KB |
Output is correct |
35 |
Correct |
47 ms |
4556 KB |
Output is correct |
36 |
Correct |
47 ms |
4544 KB |
Output is correct |
37 |
Correct |
51 ms |
4436 KB |
Output is correct |
38 |
Correct |
62 ms |
4664 KB |
Output is correct |
39 |
Correct |
68 ms |
4600 KB |
Output is correct |
40 |
Correct |
28 ms |
2892 KB |
Output is correct |
41 |
Correct |
27 ms |
2772 KB |
Output is correct |
42 |
Correct |
25 ms |
2252 KB |
Output is correct |
43 |
Correct |
24 ms |
2256 KB |
Output is correct |
44 |
Correct |
28 ms |
2776 KB |
Output is correct |
45 |
Correct |
27 ms |
2760 KB |
Output is correct |
46 |
Correct |
23 ms |
2252 KB |
Output is correct |
47 |
Correct |
26 ms |
2276 KB |
Output is correct |
48 |
Correct |
1764 ms |
49080 KB |
Output is correct |
49 |
Correct |
1654 ms |
53632 KB |
Output is correct |
50 |
Correct |
1675 ms |
53716 KB |
Output is correct |
51 |
Correct |
1595 ms |
46412 KB |
Output is correct |
52 |
Correct |
1366 ms |
37772 KB |
Output is correct |
53 |
Correct |
614 ms |
32868 KB |
Output is correct |
54 |
Correct |
429 ms |
26404 KB |
Output is correct |
55 |
Correct |
436 ms |
25960 KB |
Output is correct |
56 |
Correct |
451 ms |
23208 KB |
Output is correct |
57 |
Correct |
1496 ms |
167528 KB |
Output is correct |
58 |
Correct |
1555 ms |
127780 KB |
Output is correct |
59 |
Correct |
1575 ms |
123520 KB |
Output is correct |
60 |
Correct |
1675 ms |
134568 KB |
Output is correct |
61 |
Correct |
1464 ms |
134608 KB |
Output is correct |
62 |
Correct |
711 ms |
67448 KB |
Output is correct |
63 |
Correct |
974 ms |
89704 KB |
Output is correct |
64 |
Correct |
812 ms |
77176 KB |
Output is correct |
65 |
Correct |
508 ms |
46680 KB |
Output is correct |