#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
#define INF (int)(1e18)
using namespace std;
using LL = long long;
using pii = pair<int, int>;
void chmin(int &x, int a) {
x = min(x, a);
}
void chmax(int &x, int a) {
x = max(x, a);
}
const int MAXN = 1000010;
int ans[MAXN];
int cnt1[MAXN];
void solve(int n, int m, vector<pii> v2, vector<int> v1) {
for(auto &i:v2) {
if(i.F > i.S) swap(i.F, i.S);
} // i.F <= i.S
memset(cnt1, 0, sizeof(cnt1));
map<pii, int> cnt2;
for(auto &i:v2) {
cnt1[i.F]++;
cnt1[i.S]++;
cnt2[i]++;
}
For(c1, 1, m) {
For(c2, c1 + 1, m) {
int cost = n - cnt1[c1] - cnt1[c2] + cnt2[pii(c1, c2)];
for(auto &i:v1) {
cost -= max(i == c1, i == c2);
}
chmin(ans[c1], cost);
chmin(ans[c2], cost);
}
int cost = n - cnt1[c1];
for(auto &i:v1) cost -= (i == c1);
chmin(ans[c1], cost);
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// =^-w-^=
int n, m; cin >> n >> m;
vector<int> a(n);
for(auto &i:a) cin >> i;
For(i, 1, m) {
ans[i] = INF;
}
if(n % 2) {
For(_, 0, 1) {
vector<pii> v2;
for(int i = 1; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, { a.back() });
reverse(all(a));
}
} else {
vector<pii> v2;
for(int i = 1; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, {});
v2.clear();
for(int i = 2; i < n; i += 2) {
v2.eb(pii(a[i - 1], a[i]));
}
solve(n, m, v2, { a.front(), a.back() });
}
For(i, 1, m) cout << ans[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8080 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8036 KB |
Output is correct |
9 |
Correct |
5 ms |
8020 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
5 ms |
8152 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8128 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8080 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8036 KB |
Output is correct |
9 |
Correct |
5 ms |
8020 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
5 ms |
8152 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8128 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
16 ms |
10808 KB |
Output is correct |
28 |
Correct |
14 ms |
10828 KB |
Output is correct |
29 |
Correct |
19 ms |
10928 KB |
Output is correct |
30 |
Correct |
17 ms |
10928 KB |
Output is correct |
31 |
Correct |
18 ms |
10796 KB |
Output is correct |
32 |
Correct |
15 ms |
10832 KB |
Output is correct |
33 |
Correct |
17 ms |
10872 KB |
Output is correct |
34 |
Correct |
15 ms |
10928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8080 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8036 KB |
Output is correct |
9 |
Correct |
5 ms |
8020 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
5 ms |
8152 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8128 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
16 ms |
10808 KB |
Output is correct |
28 |
Correct |
14 ms |
10828 KB |
Output is correct |
29 |
Correct |
19 ms |
10928 KB |
Output is correct |
30 |
Correct |
17 ms |
10928 KB |
Output is correct |
31 |
Correct |
18 ms |
10796 KB |
Output is correct |
32 |
Correct |
15 ms |
10832 KB |
Output is correct |
33 |
Correct |
17 ms |
10872 KB |
Output is correct |
34 |
Correct |
15 ms |
10928 KB |
Output is correct |
35 |
Correct |
84 ms |
18632 KB |
Output is correct |
36 |
Correct |
87 ms |
18604 KB |
Output is correct |
37 |
Correct |
87 ms |
18304 KB |
Output is correct |
38 |
Correct |
99 ms |
18464 KB |
Output is correct |
39 |
Correct |
84 ms |
18856 KB |
Output is correct |
40 |
Correct |
82 ms |
18652 KB |
Output is correct |
41 |
Correct |
72 ms |
18688 KB |
Output is correct |
42 |
Correct |
72 ms |
15856 KB |
Output is correct |
43 |
Correct |
43 ms |
13568 KB |
Output is correct |
44 |
Correct |
73 ms |
18632 KB |
Output is correct |
45 |
Correct |
73 ms |
18692 KB |
Output is correct |
46 |
Correct |
58 ms |
15872 KB |
Output is correct |
47 |
Correct |
40 ms |
13672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8080 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8036 KB |
Output is correct |
9 |
Correct |
5 ms |
8020 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
5 ms |
8152 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8128 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
16 ms |
10808 KB |
Output is correct |
28 |
Correct |
14 ms |
10828 KB |
Output is correct |
29 |
Correct |
19 ms |
10928 KB |
Output is correct |
30 |
Correct |
17 ms |
10928 KB |
Output is correct |
31 |
Correct |
18 ms |
10796 KB |
Output is correct |
32 |
Correct |
15 ms |
10832 KB |
Output is correct |
33 |
Correct |
17 ms |
10872 KB |
Output is correct |
34 |
Correct |
15 ms |
10928 KB |
Output is correct |
35 |
Correct |
84 ms |
18632 KB |
Output is correct |
36 |
Correct |
87 ms |
18604 KB |
Output is correct |
37 |
Correct |
87 ms |
18304 KB |
Output is correct |
38 |
Correct |
99 ms |
18464 KB |
Output is correct |
39 |
Correct |
84 ms |
18856 KB |
Output is correct |
40 |
Correct |
82 ms |
18652 KB |
Output is correct |
41 |
Correct |
72 ms |
18688 KB |
Output is correct |
42 |
Correct |
72 ms |
15856 KB |
Output is correct |
43 |
Correct |
43 ms |
13568 KB |
Output is correct |
44 |
Correct |
73 ms |
18632 KB |
Output is correct |
45 |
Correct |
73 ms |
18692 KB |
Output is correct |
46 |
Correct |
58 ms |
15872 KB |
Output is correct |
47 |
Correct |
40 ms |
13672 KB |
Output is correct |
48 |
Runtime error |
1115 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8080 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
6 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8036 KB |
Output is correct |
9 |
Correct |
5 ms |
8020 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
5 ms |
8148 KB |
Output is correct |
12 |
Correct |
5 ms |
8152 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8128 KB |
Output is correct |
17 |
Correct |
4 ms |
8152 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
16 ms |
10808 KB |
Output is correct |
28 |
Correct |
14 ms |
10828 KB |
Output is correct |
29 |
Correct |
19 ms |
10928 KB |
Output is correct |
30 |
Correct |
17 ms |
10928 KB |
Output is correct |
31 |
Correct |
18 ms |
10796 KB |
Output is correct |
32 |
Correct |
15 ms |
10832 KB |
Output is correct |
33 |
Correct |
17 ms |
10872 KB |
Output is correct |
34 |
Correct |
15 ms |
10928 KB |
Output is correct |
35 |
Correct |
84 ms |
18632 KB |
Output is correct |
36 |
Correct |
87 ms |
18604 KB |
Output is correct |
37 |
Correct |
87 ms |
18304 KB |
Output is correct |
38 |
Correct |
99 ms |
18464 KB |
Output is correct |
39 |
Correct |
84 ms |
18856 KB |
Output is correct |
40 |
Correct |
82 ms |
18652 KB |
Output is correct |
41 |
Correct |
72 ms |
18688 KB |
Output is correct |
42 |
Correct |
72 ms |
15856 KB |
Output is correct |
43 |
Correct |
43 ms |
13568 KB |
Output is correct |
44 |
Correct |
73 ms |
18632 KB |
Output is correct |
45 |
Correct |
73 ms |
18692 KB |
Output is correct |
46 |
Correct |
58 ms |
15872 KB |
Output is correct |
47 |
Correct |
40 ms |
13672 KB |
Output is correct |
48 |
Runtime error |
1115 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |