#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
vector<int> cc[maxn];
int us[maxn];
int a[maxn];
int u[maxn];
int me[maxn];
int ans[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
for(int j = 0;j < n;++j)
{
cin >> a[j];
a[j]--;
cc[a[j]].push_back(j);
}
for(int j = 0;j < m;++j)
{
me[j] = j;
u[j] = cc[j].size();
ans[j] = n+1;
}
sort(me,me+m,[&](int a,int b){return u[a] > u[b];});
if(m == 1)
{
cout << 0;
return 0;
}
for(int j = 0;j < m;++j)
{
us[j] = 1;
int op = u[j];
int xx = 0;
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = a[cc[j][k]^1];
us[pr] = 1;
u[pr]--;
}
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = a[cc[j][k]^1];
if(pr != j)
xx = max(xx,u[pr]);
}
for(int j = 0;j < m;++j)
{
if(!us[me[j]])
{
xx = max(xx,u[me[j]]);
break;
}
}
ans[j] = min(ans[j],n-op-xx);
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = a[cc[j][k]^1];
us[pr] = 0;
u[pr]++;
}
us[j] = 0;
}
for(int j = 0;j < m;++j)
{
us[j] = 1;
int op = u[j];
int xx = 0;
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = a[((cc[j][k]-1)^1)+1];
us[pr] = 1;
u[pr]--;
}
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = a[((cc[j][k]-1)^1)+1];
if(pr != j)
xx = max(xx,u[pr]);
}
for(int j = 0;j < m;++j)
{
if(!us[me[j]])
{
xx = max(xx,u[me[j]]);
break;
}
}
ans[j] = min(ans[j],n-op-xx);
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = a[((cc[j][k]-1)^1)+1];
us[pr] = 0;
u[pr]++;
}
us[j] = 0;
cout << ans[j] << "\n";
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:51:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:68:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:83:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:93:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:112:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
32860 KB |
Output is correct |
2 |
Correct |
8 ms |
32936 KB |
Output is correct |
3 |
Correct |
8 ms |
33060 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
8 ms |
32860 KB |
Output is correct |
6 |
Correct |
7 ms |
32860 KB |
Output is correct |
7 |
Correct |
7 ms |
32860 KB |
Output is correct |
8 |
Correct |
8 ms |
32860 KB |
Output is correct |
9 |
Correct |
7 ms |
32860 KB |
Output is correct |
10 |
Correct |
10 ms |
32988 KB |
Output is correct |
11 |
Correct |
8 ms |
32860 KB |
Output is correct |
12 |
Correct |
7 ms |
32860 KB |
Output is correct |
13 |
Correct |
7 ms |
32860 KB |
Output is correct |
14 |
Correct |
8 ms |
32860 KB |
Output is correct |
15 |
Correct |
7 ms |
32856 KB |
Output is correct |
16 |
Correct |
8 ms |
33040 KB |
Output is correct |
17 |
Correct |
7 ms |
32860 KB |
Output is correct |
18 |
Correct |
7 ms |
33072 KB |
Output is correct |
19 |
Correct |
7 ms |
32860 KB |
Output is correct |
20 |
Correct |
8 ms |
32860 KB |
Output is correct |
21 |
Correct |
8 ms |
32856 KB |
Output is correct |
22 |
Correct |
7 ms |
30812 KB |
Output is correct |
23 |
Correct |
7 ms |
32860 KB |
Output is correct |
24 |
Correct |
8 ms |
32860 KB |
Output is correct |
25 |
Correct |
7 ms |
33068 KB |
Output is correct |
26 |
Correct |
7 ms |
30812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
32860 KB |
Output is correct |
2 |
Correct |
8 ms |
32936 KB |
Output is correct |
3 |
Correct |
8 ms |
33060 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
8 ms |
32860 KB |
Output is correct |
6 |
Correct |
7 ms |
32860 KB |
Output is correct |
7 |
Correct |
7 ms |
32860 KB |
Output is correct |
8 |
Correct |
8 ms |
32860 KB |
Output is correct |
9 |
Correct |
7 ms |
32860 KB |
Output is correct |
10 |
Correct |
10 ms |
32988 KB |
Output is correct |
11 |
Correct |
8 ms |
32860 KB |
Output is correct |
12 |
Correct |
7 ms |
32860 KB |
Output is correct |
13 |
Correct |
7 ms |
32860 KB |
Output is correct |
14 |
Correct |
8 ms |
32860 KB |
Output is correct |
15 |
Correct |
7 ms |
32856 KB |
Output is correct |
16 |
Correct |
8 ms |
33040 KB |
Output is correct |
17 |
Correct |
7 ms |
32860 KB |
Output is correct |
18 |
Correct |
7 ms |
33072 KB |
Output is correct |
19 |
Correct |
7 ms |
32860 KB |
Output is correct |
20 |
Correct |
8 ms |
32860 KB |
Output is correct |
21 |
Correct |
8 ms |
32856 KB |
Output is correct |
22 |
Correct |
7 ms |
30812 KB |
Output is correct |
23 |
Correct |
7 ms |
32860 KB |
Output is correct |
24 |
Correct |
8 ms |
32860 KB |
Output is correct |
25 |
Correct |
7 ms |
33068 KB |
Output is correct |
26 |
Correct |
7 ms |
30812 KB |
Output is correct |
27 |
Correct |
12 ms |
33628 KB |
Output is correct |
28 |
Correct |
16 ms |
33640 KB |
Output is correct |
29 |
Correct |
12 ms |
33628 KB |
Output is correct |
30 |
Correct |
12 ms |
33496 KB |
Output is correct |
31 |
Correct |
12 ms |
33628 KB |
Output is correct |
32 |
Correct |
14 ms |
33704 KB |
Output is correct |
33 |
Correct |
12 ms |
33628 KB |
Output is correct |
34 |
Correct |
12 ms |
33564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
32860 KB |
Output is correct |
2 |
Correct |
8 ms |
32936 KB |
Output is correct |
3 |
Correct |
8 ms |
33060 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
8 ms |
32860 KB |
Output is correct |
6 |
Correct |
7 ms |
32860 KB |
Output is correct |
7 |
Correct |
7 ms |
32860 KB |
Output is correct |
8 |
Correct |
8 ms |
32860 KB |
Output is correct |
9 |
Correct |
7 ms |
32860 KB |
Output is correct |
10 |
Correct |
10 ms |
32988 KB |
Output is correct |
11 |
Correct |
8 ms |
32860 KB |
Output is correct |
12 |
Correct |
7 ms |
32860 KB |
Output is correct |
13 |
Correct |
7 ms |
32860 KB |
Output is correct |
14 |
Correct |
8 ms |
32860 KB |
Output is correct |
15 |
Correct |
7 ms |
32856 KB |
Output is correct |
16 |
Correct |
8 ms |
33040 KB |
Output is correct |
17 |
Correct |
7 ms |
32860 KB |
Output is correct |
18 |
Correct |
7 ms |
33072 KB |
Output is correct |
19 |
Correct |
7 ms |
32860 KB |
Output is correct |
20 |
Correct |
8 ms |
32860 KB |
Output is correct |
21 |
Correct |
8 ms |
32856 KB |
Output is correct |
22 |
Correct |
7 ms |
30812 KB |
Output is correct |
23 |
Correct |
7 ms |
32860 KB |
Output is correct |
24 |
Correct |
8 ms |
32860 KB |
Output is correct |
25 |
Correct |
7 ms |
33068 KB |
Output is correct |
26 |
Correct |
7 ms |
30812 KB |
Output is correct |
27 |
Correct |
12 ms |
33628 KB |
Output is correct |
28 |
Correct |
16 ms |
33640 KB |
Output is correct |
29 |
Correct |
12 ms |
33628 KB |
Output is correct |
30 |
Correct |
12 ms |
33496 KB |
Output is correct |
31 |
Correct |
12 ms |
33628 KB |
Output is correct |
32 |
Correct |
14 ms |
33704 KB |
Output is correct |
33 |
Correct |
12 ms |
33628 KB |
Output is correct |
34 |
Correct |
12 ms |
33564 KB |
Output is correct |
35 |
Correct |
13 ms |
33628 KB |
Output is correct |
36 |
Correct |
14 ms |
33624 KB |
Output is correct |
37 |
Correct |
14 ms |
33628 KB |
Output is correct |
38 |
Correct |
14 ms |
33488 KB |
Output is correct |
39 |
Correct |
14 ms |
33628 KB |
Output is correct |
40 |
Correct |
14 ms |
33628 KB |
Output is correct |
41 |
Correct |
14 ms |
33624 KB |
Output is correct |
42 |
Correct |
13 ms |
33692 KB |
Output is correct |
43 |
Correct |
13 ms |
33672 KB |
Output is correct |
44 |
Correct |
18 ms |
33716 KB |
Output is correct |
45 |
Correct |
13 ms |
33624 KB |
Output is correct |
46 |
Correct |
14 ms |
33624 KB |
Output is correct |
47 |
Correct |
14 ms |
33628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
32860 KB |
Output is correct |
2 |
Correct |
8 ms |
32936 KB |
Output is correct |
3 |
Correct |
8 ms |
33060 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
8 ms |
32860 KB |
Output is correct |
6 |
Correct |
7 ms |
32860 KB |
Output is correct |
7 |
Correct |
7 ms |
32860 KB |
Output is correct |
8 |
Correct |
8 ms |
32860 KB |
Output is correct |
9 |
Correct |
7 ms |
32860 KB |
Output is correct |
10 |
Correct |
10 ms |
32988 KB |
Output is correct |
11 |
Correct |
8 ms |
32860 KB |
Output is correct |
12 |
Correct |
7 ms |
32860 KB |
Output is correct |
13 |
Correct |
7 ms |
32860 KB |
Output is correct |
14 |
Correct |
8 ms |
32860 KB |
Output is correct |
15 |
Correct |
7 ms |
32856 KB |
Output is correct |
16 |
Correct |
8 ms |
33040 KB |
Output is correct |
17 |
Correct |
7 ms |
32860 KB |
Output is correct |
18 |
Correct |
7 ms |
33072 KB |
Output is correct |
19 |
Correct |
7 ms |
32860 KB |
Output is correct |
20 |
Correct |
8 ms |
32860 KB |
Output is correct |
21 |
Correct |
8 ms |
32856 KB |
Output is correct |
22 |
Correct |
7 ms |
30812 KB |
Output is correct |
23 |
Correct |
7 ms |
32860 KB |
Output is correct |
24 |
Correct |
8 ms |
32860 KB |
Output is correct |
25 |
Correct |
7 ms |
33068 KB |
Output is correct |
26 |
Correct |
7 ms |
30812 KB |
Output is correct |
27 |
Correct |
12 ms |
33628 KB |
Output is correct |
28 |
Correct |
16 ms |
33640 KB |
Output is correct |
29 |
Correct |
12 ms |
33628 KB |
Output is correct |
30 |
Correct |
12 ms |
33496 KB |
Output is correct |
31 |
Correct |
12 ms |
33628 KB |
Output is correct |
32 |
Correct |
14 ms |
33704 KB |
Output is correct |
33 |
Correct |
12 ms |
33628 KB |
Output is correct |
34 |
Correct |
12 ms |
33564 KB |
Output is correct |
35 |
Correct |
13 ms |
33628 KB |
Output is correct |
36 |
Correct |
14 ms |
33624 KB |
Output is correct |
37 |
Correct |
14 ms |
33628 KB |
Output is correct |
38 |
Correct |
14 ms |
33488 KB |
Output is correct |
39 |
Correct |
14 ms |
33628 KB |
Output is correct |
40 |
Correct |
14 ms |
33628 KB |
Output is correct |
41 |
Correct |
14 ms |
33624 KB |
Output is correct |
42 |
Correct |
13 ms |
33692 KB |
Output is correct |
43 |
Correct |
13 ms |
33672 KB |
Output is correct |
44 |
Correct |
18 ms |
33716 KB |
Output is correct |
45 |
Correct |
13 ms |
33624 KB |
Output is correct |
46 |
Correct |
14 ms |
33624 KB |
Output is correct |
47 |
Correct |
14 ms |
33628 KB |
Output is correct |
48 |
Correct |
89 ms |
41552 KB |
Output is correct |
49 |
Correct |
85 ms |
41556 KB |
Output is correct |
50 |
Correct |
84 ms |
41556 KB |
Output is correct |
51 |
Correct |
84 ms |
41552 KB |
Output is correct |
52 |
Correct |
73 ms |
40664 KB |
Output is correct |
53 |
Correct |
78 ms |
40956 KB |
Output is correct |
54 |
Correct |
74 ms |
39764 KB |
Output is correct |
55 |
Correct |
78 ms |
39760 KB |
Output is correct |
56 |
Correct |
73 ms |
39508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
32860 KB |
Output is correct |
2 |
Correct |
8 ms |
32936 KB |
Output is correct |
3 |
Correct |
8 ms |
33060 KB |
Output is correct |
4 |
Correct |
7 ms |
33112 KB |
Output is correct |
5 |
Correct |
8 ms |
32860 KB |
Output is correct |
6 |
Correct |
7 ms |
32860 KB |
Output is correct |
7 |
Correct |
7 ms |
32860 KB |
Output is correct |
8 |
Correct |
8 ms |
32860 KB |
Output is correct |
9 |
Correct |
7 ms |
32860 KB |
Output is correct |
10 |
Correct |
10 ms |
32988 KB |
Output is correct |
11 |
Correct |
8 ms |
32860 KB |
Output is correct |
12 |
Correct |
7 ms |
32860 KB |
Output is correct |
13 |
Correct |
7 ms |
32860 KB |
Output is correct |
14 |
Correct |
8 ms |
32860 KB |
Output is correct |
15 |
Correct |
7 ms |
32856 KB |
Output is correct |
16 |
Correct |
8 ms |
33040 KB |
Output is correct |
17 |
Correct |
7 ms |
32860 KB |
Output is correct |
18 |
Correct |
7 ms |
33072 KB |
Output is correct |
19 |
Correct |
7 ms |
32860 KB |
Output is correct |
20 |
Correct |
8 ms |
32860 KB |
Output is correct |
21 |
Correct |
8 ms |
32856 KB |
Output is correct |
22 |
Correct |
7 ms |
30812 KB |
Output is correct |
23 |
Correct |
7 ms |
32860 KB |
Output is correct |
24 |
Correct |
8 ms |
32860 KB |
Output is correct |
25 |
Correct |
7 ms |
33068 KB |
Output is correct |
26 |
Correct |
7 ms |
30812 KB |
Output is correct |
27 |
Correct |
12 ms |
33628 KB |
Output is correct |
28 |
Correct |
16 ms |
33640 KB |
Output is correct |
29 |
Correct |
12 ms |
33628 KB |
Output is correct |
30 |
Correct |
12 ms |
33496 KB |
Output is correct |
31 |
Correct |
12 ms |
33628 KB |
Output is correct |
32 |
Correct |
14 ms |
33704 KB |
Output is correct |
33 |
Correct |
12 ms |
33628 KB |
Output is correct |
34 |
Correct |
12 ms |
33564 KB |
Output is correct |
35 |
Correct |
13 ms |
33628 KB |
Output is correct |
36 |
Correct |
14 ms |
33624 KB |
Output is correct |
37 |
Correct |
14 ms |
33628 KB |
Output is correct |
38 |
Correct |
14 ms |
33488 KB |
Output is correct |
39 |
Correct |
14 ms |
33628 KB |
Output is correct |
40 |
Correct |
14 ms |
33628 KB |
Output is correct |
41 |
Correct |
14 ms |
33624 KB |
Output is correct |
42 |
Correct |
13 ms |
33692 KB |
Output is correct |
43 |
Correct |
13 ms |
33672 KB |
Output is correct |
44 |
Correct |
18 ms |
33716 KB |
Output is correct |
45 |
Correct |
13 ms |
33624 KB |
Output is correct |
46 |
Correct |
14 ms |
33624 KB |
Output is correct |
47 |
Correct |
14 ms |
33628 KB |
Output is correct |
48 |
Correct |
89 ms |
41552 KB |
Output is correct |
49 |
Correct |
85 ms |
41556 KB |
Output is correct |
50 |
Correct |
84 ms |
41556 KB |
Output is correct |
51 |
Correct |
84 ms |
41552 KB |
Output is correct |
52 |
Correct |
73 ms |
40664 KB |
Output is correct |
53 |
Correct |
78 ms |
40956 KB |
Output is correct |
54 |
Correct |
74 ms |
39764 KB |
Output is correct |
55 |
Correct |
78 ms |
39760 KB |
Output is correct |
56 |
Correct |
73 ms |
39508 KB |
Output is correct |
57 |
Correct |
804 ms |
81748 KB |
Output is correct |
58 |
Correct |
493 ms |
73044 KB |
Output is correct |
59 |
Correct |
575 ms |
73032 KB |
Output is correct |
60 |
Correct |
584 ms |
76852 KB |
Output is correct |
61 |
Correct |
621 ms |
77172 KB |
Output is correct |
62 |
Correct |
220 ms |
62620 KB |
Output is correct |
63 |
Correct |
323 ms |
68688 KB |
Output is correct |
64 |
Correct |
348 ms |
66128 KB |
Output is correct |
65 |
Correct |
134 ms |
57232 KB |
Output is correct |