// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<int> a;
vector<int> cnt1, cnt2;
map<array<int,2>, int> mpp1, mpp2;
inline void solve() {
cin>>n>>m;
a.resize(n + 1);
cnt1.assign(m + 1, 0);
cnt2.assign(m + 1, 0);
for(int i = 1; i<=n; i++) {
cin >> a[i];
}
for(int i = 1; i<n; i+=2) {
cnt1[a[i]]++;
cnt1[a[i + 1]]++;
mpp1[{min(a[i], a[i + 1]), max(a[i], a[i + 1])}]++;
}
for(int i = 2; i<n; i+=2) {
cnt2[a[i]]++;
cnt2[a[i + 1]]++;
mpp2[{min(a[i], a[i + 1]), max(a[i], a[i + 1])}]++;
}
vector<int> res(m + 1, INF);
for(int i = 1; i <= m; i++) {
for(int j = i + 1; j <= m; j++) {
int ret = n;
if((n & 1) && (a[n] == i || a[n] == j)) {
ret--;
}
ret -= cnt1[i] + cnt1[j];
ret += mpp1[{i, j}];
res[i] = min(res[i], ret);
res[j] = min(res[j], ret);
ret = n;
if(!(n & 1) && (a[n] == i || a[n] == j)) {
ret--;
}
if(a[1] == i || a[1] == j) {
ret--;
}
ret -= cnt2[i] + cnt2[j];
ret += mpp2[{i, j}];
res[i] = min(res[i], ret);
res[j] = min(res[j], ret);
}
}
for(int i = 1; i<=m; i++) {
int ret = n - cnt1[i];
if((n & 1) && a[n] == i) ret--;
res[i] = min(res[i], ret);
cout << res[i] << "\n";
}
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
600 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 |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
456 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
600 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 |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
456 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
1116 KB |
Output is correct |
28 |
Correct |
10 ms |
860 KB |
Output is correct |
29 |
Correct |
9 ms |
860 KB |
Output is correct |
30 |
Correct |
7 ms |
1112 KB |
Output is correct |
31 |
Correct |
9 ms |
860 KB |
Output is correct |
32 |
Correct |
7 ms |
860 KB |
Output is correct |
33 |
Correct |
8 ms |
968 KB |
Output is correct |
34 |
Correct |
7 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
600 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 |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
456 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
1116 KB |
Output is correct |
28 |
Correct |
10 ms |
860 KB |
Output is correct |
29 |
Correct |
9 ms |
860 KB |
Output is correct |
30 |
Correct |
7 ms |
1112 KB |
Output is correct |
31 |
Correct |
9 ms |
860 KB |
Output is correct |
32 |
Correct |
7 ms |
860 KB |
Output is correct |
33 |
Correct |
8 ms |
968 KB |
Output is correct |
34 |
Correct |
7 ms |
856 KB |
Output is correct |
35 |
Correct |
70 ms |
16696 KB |
Output is correct |
36 |
Correct |
68 ms |
16724 KB |
Output is correct |
37 |
Correct |
74 ms |
15584 KB |
Output is correct |
38 |
Correct |
68 ms |
15964 KB |
Output is correct |
39 |
Correct |
78 ms |
16724 KB |
Output is correct |
40 |
Correct |
67 ms |
16640 KB |
Output is correct |
41 |
Correct |
67 ms |
16776 KB |
Output is correct |
42 |
Correct |
46 ms |
11060 KB |
Output is correct |
43 |
Correct |
38 ms |
6584 KB |
Output is correct |
44 |
Correct |
61 ms |
16732 KB |
Output is correct |
45 |
Correct |
79 ms |
16636 KB |
Output is correct |
46 |
Correct |
51 ms |
11088 KB |
Output is correct |
47 |
Correct |
30 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
600 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 |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
456 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
1116 KB |
Output is correct |
28 |
Correct |
10 ms |
860 KB |
Output is correct |
29 |
Correct |
9 ms |
860 KB |
Output is correct |
30 |
Correct |
7 ms |
1112 KB |
Output is correct |
31 |
Correct |
9 ms |
860 KB |
Output is correct |
32 |
Correct |
7 ms |
860 KB |
Output is correct |
33 |
Correct |
8 ms |
968 KB |
Output is correct |
34 |
Correct |
7 ms |
856 KB |
Output is correct |
35 |
Correct |
70 ms |
16696 KB |
Output is correct |
36 |
Correct |
68 ms |
16724 KB |
Output is correct |
37 |
Correct |
74 ms |
15584 KB |
Output is correct |
38 |
Correct |
68 ms |
15964 KB |
Output is correct |
39 |
Correct |
78 ms |
16724 KB |
Output is correct |
40 |
Correct |
67 ms |
16640 KB |
Output is correct |
41 |
Correct |
67 ms |
16776 KB |
Output is correct |
42 |
Correct |
46 ms |
11060 KB |
Output is correct |
43 |
Correct |
38 ms |
6584 KB |
Output is correct |
44 |
Correct |
61 ms |
16732 KB |
Output is correct |
45 |
Correct |
79 ms |
16636 KB |
Output is correct |
46 |
Correct |
51 ms |
11088 KB |
Output is correct |
47 |
Correct |
30 ms |
6736 KB |
Output is correct |
48 |
Runtime error |
1364 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
600 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 |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
456 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
11 ms |
1116 KB |
Output is correct |
28 |
Correct |
10 ms |
860 KB |
Output is correct |
29 |
Correct |
9 ms |
860 KB |
Output is correct |
30 |
Correct |
7 ms |
1112 KB |
Output is correct |
31 |
Correct |
9 ms |
860 KB |
Output is correct |
32 |
Correct |
7 ms |
860 KB |
Output is correct |
33 |
Correct |
8 ms |
968 KB |
Output is correct |
34 |
Correct |
7 ms |
856 KB |
Output is correct |
35 |
Correct |
70 ms |
16696 KB |
Output is correct |
36 |
Correct |
68 ms |
16724 KB |
Output is correct |
37 |
Correct |
74 ms |
15584 KB |
Output is correct |
38 |
Correct |
68 ms |
15964 KB |
Output is correct |
39 |
Correct |
78 ms |
16724 KB |
Output is correct |
40 |
Correct |
67 ms |
16640 KB |
Output is correct |
41 |
Correct |
67 ms |
16776 KB |
Output is correct |
42 |
Correct |
46 ms |
11060 KB |
Output is correct |
43 |
Correct |
38 ms |
6584 KB |
Output is correct |
44 |
Correct |
61 ms |
16732 KB |
Output is correct |
45 |
Correct |
79 ms |
16636 KB |
Output is correct |
46 |
Correct |
51 ms |
11088 KB |
Output is correct |
47 |
Correct |
30 ms |
6736 KB |
Output is correct |
48 |
Runtime error |
1364 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |