#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int n, m;
cin >> n >> m;
int a[n], K[n+1], K1[n+1], KY[n+1], G[n+1], Re[m+1], Ma=0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
K[i] = 0;
KY[i] = 0;
}
K[n] = 0;
KY[n] = 0;
vector <int> V[n+1], Ch;
for (int i = 0; i < n; i += 2)
{
if (i == n-1)
{
K[a[i]]++;
}
else
{
K[a[i]]++;
K[a[i+1]]++;
if (a[i] != a[i+1])
{
V[a[i]].push_back(a[i+1]);
V[a[i+1]].push_back(a[i]);
}
}
}
for (int i = 1; i <= m; i++)
{
K1[i] = K[i];
KY[K[i]]++;
G[i] = 1;
Ma = max(Ma, K[i]);
}
for (int i = 1; i <= m; i++)
{
Re[i] = 0;
G[i] = 0;
Ch.push_back(i);
KY[K[i]]--;
KY[0]++;
K1[i] = 0;
while (KY[Ma] == 0)
{
Ma--;
}
for (int y = 0; y < V[i].size(); y++)
{
int A = V[i][y];
KY[K1[A]]--;
K1[A]--;
KY[K1[A]]++;
while (KY[Ma] == 0)
{
Ma--;
}
if (G[A] == 1)
{
G[A] = 0;
Ch.push_back(A);
}
}
Re[i] = n - Ma - K[i];
for (int y = 0; y < Ch.size(); y++)
{
int A = Ch[y];
G[A] = 1;
KY[K1[A]]--;
KY[K[A]]++;
K1[A] = K[A];
Ma = max(Ma, K[A]);
}
Ch.clear();
}
for (int i = 0; i <= n; i++)
{
V[i].clear();
K[i] = 0;
KY[i] = 0;
} //
K[a[0]]++;
for (int i = 1; i < n; i += 2)
{
if (i == n-1)
{
K[a[i]]++;
}
else
{
K[a[i]]++;
K[a[i+1]]++;
if (a[i] != a[i+1])
{
V[a[i]].push_back(a[i+1]);
V[a[i+1]].push_back(a[i]);
}
}
}
for (int i = 1; i <= m; i++)
{
K1[i] = K[i];
KY[K[i]]++;
G[i] = 1;
Ma = max(Ma, K[i]);
}
for (int i = 1; i <= m; i++)
{
G[i] = 0;
Ch.push_back(i);
KY[K[i]]--;
K1[i] = 0;
KY[0]++;
while (KY[Ma] == 0)
{
Ma--;
}
for (int y = 0; y < V[i].size(); y++)
{
int A = V[i][y];
KY[K1[A]]--;
K1[A]--;
KY[K1[A]]++;
if (KY[Ma] == 0)
{
Ma--;
}
if (G[A] == 1)
{
G[A] = 0;
Ch.push_back(A);
}
}
Re[i] = min(n - Ma - K[i], Re[i]);
for (int y = 0; y < Ch.size(); y++)
{
int A = Ch[y];
G[A] = 1;
KY[K1[A]]--;
KY[K[A]]++;
K1[A] = K[A];
Ma = max(Ma, K[A]);
}
Ch.clear();
}
for (int i = 1; i <= m; i++)
{
cout << Re[i] << "\n";
}
return 0;
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:55:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < V[i].size(); y++)
~~^~~~~~~~~~~~~
rope.cpp:72:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < Ch.size(); y++)
~~^~~~~~~~~~~
rope.cpp:126:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < V[i].size(); y++)
~~^~~~~~~~~~~~~
rope.cpp:143:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < Ch.size(); y++)
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
4736 KB |
Output is correct |
28 |
Correct |
13 ms |
4608 KB |
Output is correct |
29 |
Correct |
13 ms |
4608 KB |
Output is correct |
30 |
Correct |
18 ms |
4480 KB |
Output is correct |
31 |
Correct |
14 ms |
4736 KB |
Output is correct |
32 |
Correct |
14 ms |
4608 KB |
Output is correct |
33 |
Correct |
15 ms |
4608 KB |
Output is correct |
34 |
Correct |
13 ms |
4480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
4736 KB |
Output is correct |
28 |
Correct |
13 ms |
4608 KB |
Output is correct |
29 |
Correct |
13 ms |
4608 KB |
Output is correct |
30 |
Correct |
18 ms |
4480 KB |
Output is correct |
31 |
Correct |
14 ms |
4736 KB |
Output is correct |
32 |
Correct |
14 ms |
4608 KB |
Output is correct |
33 |
Correct |
15 ms |
4608 KB |
Output is correct |
34 |
Correct |
13 ms |
4480 KB |
Output is correct |
35 |
Correct |
19 ms |
4864 KB |
Output is correct |
36 |
Correct |
19 ms |
4864 KB |
Output is correct |
37 |
Correct |
25 ms |
4736 KB |
Output is correct |
38 |
Correct |
19 ms |
4864 KB |
Output is correct |
39 |
Correct |
18 ms |
4864 KB |
Output is correct |
40 |
Correct |
17 ms |
4992 KB |
Output is correct |
41 |
Correct |
18 ms |
4864 KB |
Output is correct |
42 |
Correct |
16 ms |
4864 KB |
Output is correct |
43 |
Correct |
16 ms |
4864 KB |
Output is correct |
44 |
Correct |
17 ms |
4864 KB |
Output is correct |
45 |
Correct |
17 ms |
4864 KB |
Output is correct |
46 |
Correct |
16 ms |
4864 KB |
Output is correct |
47 |
Correct |
17 ms |
4864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
4736 KB |
Output is correct |
28 |
Correct |
13 ms |
4608 KB |
Output is correct |
29 |
Correct |
13 ms |
4608 KB |
Output is correct |
30 |
Correct |
18 ms |
4480 KB |
Output is correct |
31 |
Correct |
14 ms |
4736 KB |
Output is correct |
32 |
Correct |
14 ms |
4608 KB |
Output is correct |
33 |
Correct |
15 ms |
4608 KB |
Output is correct |
34 |
Correct |
13 ms |
4480 KB |
Output is correct |
35 |
Correct |
19 ms |
4864 KB |
Output is correct |
36 |
Correct |
19 ms |
4864 KB |
Output is correct |
37 |
Correct |
25 ms |
4736 KB |
Output is correct |
38 |
Correct |
19 ms |
4864 KB |
Output is correct |
39 |
Correct |
18 ms |
4864 KB |
Output is correct |
40 |
Correct |
17 ms |
4992 KB |
Output is correct |
41 |
Correct |
18 ms |
4864 KB |
Output is correct |
42 |
Correct |
16 ms |
4864 KB |
Output is correct |
43 |
Correct |
16 ms |
4864 KB |
Output is correct |
44 |
Correct |
17 ms |
4864 KB |
Output is correct |
45 |
Correct |
17 ms |
4864 KB |
Output is correct |
46 |
Correct |
16 ms |
4864 KB |
Output is correct |
47 |
Correct |
17 ms |
4864 KB |
Output is correct |
48 |
Correct |
214 ms |
46840 KB |
Output is correct |
49 |
Correct |
214 ms |
46840 KB |
Output is correct |
50 |
Correct |
202 ms |
46712 KB |
Output is correct |
51 |
Correct |
197 ms |
46328 KB |
Output is correct |
52 |
Correct |
180 ms |
44924 KB |
Output is correct |
53 |
Correct |
179 ms |
45948 KB |
Output is correct |
54 |
Correct |
174 ms |
44920 KB |
Output is correct |
55 |
Correct |
181 ms |
44792 KB |
Output is correct |
56 |
Correct |
177 ms |
44536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
4736 KB |
Output is correct |
28 |
Correct |
13 ms |
4608 KB |
Output is correct |
29 |
Correct |
13 ms |
4608 KB |
Output is correct |
30 |
Correct |
18 ms |
4480 KB |
Output is correct |
31 |
Correct |
14 ms |
4736 KB |
Output is correct |
32 |
Correct |
14 ms |
4608 KB |
Output is correct |
33 |
Correct |
15 ms |
4608 KB |
Output is correct |
34 |
Correct |
13 ms |
4480 KB |
Output is correct |
35 |
Correct |
19 ms |
4864 KB |
Output is correct |
36 |
Correct |
19 ms |
4864 KB |
Output is correct |
37 |
Correct |
25 ms |
4736 KB |
Output is correct |
38 |
Correct |
19 ms |
4864 KB |
Output is correct |
39 |
Correct |
18 ms |
4864 KB |
Output is correct |
40 |
Correct |
17 ms |
4992 KB |
Output is correct |
41 |
Correct |
18 ms |
4864 KB |
Output is correct |
42 |
Correct |
16 ms |
4864 KB |
Output is correct |
43 |
Correct |
16 ms |
4864 KB |
Output is correct |
44 |
Correct |
17 ms |
4864 KB |
Output is correct |
45 |
Correct |
17 ms |
4864 KB |
Output is correct |
46 |
Correct |
16 ms |
4864 KB |
Output is correct |
47 |
Correct |
17 ms |
4864 KB |
Output is correct |
48 |
Correct |
214 ms |
46840 KB |
Output is correct |
49 |
Correct |
214 ms |
46840 KB |
Output is correct |
50 |
Correct |
202 ms |
46712 KB |
Output is correct |
51 |
Correct |
197 ms |
46328 KB |
Output is correct |
52 |
Correct |
180 ms |
44924 KB |
Output is correct |
53 |
Correct |
179 ms |
45948 KB |
Output is correct |
54 |
Correct |
174 ms |
44920 KB |
Output is correct |
55 |
Correct |
181 ms |
44792 KB |
Output is correct |
56 |
Correct |
177 ms |
44536 KB |
Output is correct |
57 |
Correct |
1327 ms |
92408 KB |
Output is correct |
58 |
Correct |
1087 ms |
72288 KB |
Output is correct |
59 |
Correct |
1047 ms |
72220 KB |
Output is correct |
60 |
Correct |
1196 ms |
77288 KB |
Output is correct |
61 |
Correct |
1144 ms |
77304 KB |
Output is correct |
62 |
Correct |
465 ms |
60152 KB |
Output is correct |
63 |
Correct |
693 ms |
65784 KB |
Output is correct |
64 |
Correct |
573 ms |
62328 KB |
Output is correct |
65 |
Correct |
307 ms |
53240 KB |
Output is correct |