#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
int dp[2][5001][5001];
int cnt[5001];
int a[1001000];
void solve(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
cnt[a[i]] ++;
}
int h[2]={0, 0};
for(int i=1; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
dp[1][l][r] ++;
dp[1][r][l] ++;
h[1] ++;
}
for(int i=2; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
dp[0][l][r] ++;
dp[0][r][l] ++;
h[0] ++;
}
for(int i=1; i<=m; i++){
int ans = n - cnt[i];
for(int j=1; j<=m; j++){
if(i == j) continue;
for(int k=0; k<2; k++){
ans = min(ans, n - cnt[i] - cnt[j] + dp[k][i][j]);
}
}
cout<<ans<<'\n';
}
}
signed main(){
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
9 ms |
6744 KB |
Output is correct |
28 |
Correct |
9 ms |
6748 KB |
Output is correct |
29 |
Correct |
9 ms |
6968 KB |
Output is correct |
30 |
Correct |
9 ms |
6744 KB |
Output is correct |
31 |
Correct |
10 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6888 KB |
Output is correct |
33 |
Correct |
9 ms |
6856 KB |
Output is correct |
34 |
Correct |
9 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
9 ms |
6744 KB |
Output is correct |
28 |
Correct |
9 ms |
6748 KB |
Output is correct |
29 |
Correct |
9 ms |
6968 KB |
Output is correct |
30 |
Correct |
9 ms |
6744 KB |
Output is correct |
31 |
Correct |
10 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6888 KB |
Output is correct |
33 |
Correct |
9 ms |
6856 KB |
Output is correct |
34 |
Correct |
9 ms |
6748 KB |
Output is correct |
35 |
Correct |
15 ms |
27456 KB |
Output is correct |
36 |
Correct |
24 ms |
27768 KB |
Output is correct |
37 |
Correct |
14 ms |
27484 KB |
Output is correct |
38 |
Correct |
15 ms |
27484 KB |
Output is correct |
39 |
Correct |
14 ms |
27624 KB |
Output is correct |
40 |
Correct |
15 ms |
27672 KB |
Output is correct |
41 |
Correct |
14 ms |
27480 KB |
Output is correct |
42 |
Correct |
14 ms |
23516 KB |
Output is correct |
43 |
Correct |
13 ms |
19288 KB |
Output is correct |
44 |
Correct |
15 ms |
27480 KB |
Output is correct |
45 |
Correct |
14 ms |
27484 KB |
Output is correct |
46 |
Correct |
13 ms |
23388 KB |
Output is correct |
47 |
Correct |
13 ms |
19292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
9 ms |
6744 KB |
Output is correct |
28 |
Correct |
9 ms |
6748 KB |
Output is correct |
29 |
Correct |
9 ms |
6968 KB |
Output is correct |
30 |
Correct |
9 ms |
6744 KB |
Output is correct |
31 |
Correct |
10 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6888 KB |
Output is correct |
33 |
Correct |
9 ms |
6856 KB |
Output is correct |
34 |
Correct |
9 ms |
6748 KB |
Output is correct |
35 |
Correct |
15 ms |
27456 KB |
Output is correct |
36 |
Correct |
24 ms |
27768 KB |
Output is correct |
37 |
Correct |
14 ms |
27484 KB |
Output is correct |
38 |
Correct |
15 ms |
27484 KB |
Output is correct |
39 |
Correct |
14 ms |
27624 KB |
Output is correct |
40 |
Correct |
15 ms |
27672 KB |
Output is correct |
41 |
Correct |
14 ms |
27480 KB |
Output is correct |
42 |
Correct |
14 ms |
23516 KB |
Output is correct |
43 |
Correct |
13 ms |
19288 KB |
Output is correct |
44 |
Correct |
15 ms |
27480 KB |
Output is correct |
45 |
Correct |
14 ms |
27484 KB |
Output is correct |
46 |
Correct |
13 ms |
23388 KB |
Output is correct |
47 |
Correct |
13 ms |
19292 KB |
Output is correct |
48 |
Correct |
166 ms |
119888 KB |
Output is correct |
49 |
Correct |
169 ms |
119892 KB |
Output is correct |
50 |
Correct |
168 ms |
119892 KB |
Output is correct |
51 |
Correct |
143 ms |
70352 KB |
Output is correct |
52 |
Correct |
121 ms |
51424 KB |
Output is correct |
53 |
Correct |
165 ms |
119004 KB |
Output is correct |
54 |
Correct |
164 ms |
118864 KB |
Output is correct |
55 |
Correct |
159 ms |
118864 KB |
Output is correct |
56 |
Correct |
161 ms |
117840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
9 ms |
6744 KB |
Output is correct |
28 |
Correct |
9 ms |
6748 KB |
Output is correct |
29 |
Correct |
9 ms |
6968 KB |
Output is correct |
30 |
Correct |
9 ms |
6744 KB |
Output is correct |
31 |
Correct |
10 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6888 KB |
Output is correct |
33 |
Correct |
9 ms |
6856 KB |
Output is correct |
34 |
Correct |
9 ms |
6748 KB |
Output is correct |
35 |
Correct |
15 ms |
27456 KB |
Output is correct |
36 |
Correct |
24 ms |
27768 KB |
Output is correct |
37 |
Correct |
14 ms |
27484 KB |
Output is correct |
38 |
Correct |
15 ms |
27484 KB |
Output is correct |
39 |
Correct |
14 ms |
27624 KB |
Output is correct |
40 |
Correct |
15 ms |
27672 KB |
Output is correct |
41 |
Correct |
14 ms |
27480 KB |
Output is correct |
42 |
Correct |
14 ms |
23516 KB |
Output is correct |
43 |
Correct |
13 ms |
19288 KB |
Output is correct |
44 |
Correct |
15 ms |
27480 KB |
Output is correct |
45 |
Correct |
14 ms |
27484 KB |
Output is correct |
46 |
Correct |
13 ms |
23388 KB |
Output is correct |
47 |
Correct |
13 ms |
19292 KB |
Output is correct |
48 |
Correct |
166 ms |
119888 KB |
Output is correct |
49 |
Correct |
169 ms |
119892 KB |
Output is correct |
50 |
Correct |
168 ms |
119892 KB |
Output is correct |
51 |
Correct |
143 ms |
70352 KB |
Output is correct |
52 |
Correct |
121 ms |
51424 KB |
Output is correct |
53 |
Correct |
165 ms |
119004 KB |
Output is correct |
54 |
Correct |
164 ms |
118864 KB |
Output is correct |
55 |
Correct |
159 ms |
118864 KB |
Output is correct |
56 |
Correct |
161 ms |
117840 KB |
Output is correct |
57 |
Runtime error |
186 ms |
24148 KB |
Execution killed with signal 11 |
58 |
Halted |
0 ms |
0 KB |
- |