#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;
int n, m, a[1000005];
int ans[1000005], occ[1000005], sum;
vector<int> pnt[1000005];
void get_table(int s, int e){
sum = 0;
memset(occ, 0, sizeof(occ));
for(int i=1; i<=n; i++) pnt[i].clear();
for(int i=s+1; i<=e; i+=2){
if(a[i-1] == a[i]){
sum += 2;
occ[a[i]] += 2;
pnt[a[i]].push_back(a[i]);
pnt[a[i]].push_back(a[i]);
}
else{
int x = a[i-1], y = a[i];
sum += 2;
occ[x]++;
occ[y]++;
pnt[x].push_back(x);
pnt[x].push_back(y);
pnt[y].push_back(x);
pnt[y].push_back(y);
}
}
}
int chk[1000005];
void sweep(){
vector<pi> v;
for(int i=1; i<=n; i++) v.push_back(pi(occ[i], i));
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for(int i=1; i<=m; i++){
int cur = -1e9;
for(auto &j : pnt[i]) chk[j]++;
for(auto &j : v){
cur = max(cur, j.first - chk[j.second]);
if(!chk[j.second]) break;
}
for(auto &j : pnt[i]) chk[j]--;
ans[i] = min(ans[i], sum - occ[i] - cur);
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
}
if(m > 5000) return 0;
memset(ans, 0x3f, sizeof(ans));
if(n % 2 == 0){
get_table(1, n);
sweep();
get_table(2, n-1);
sum += 2;
occ[a[1]]++;
occ[a[n]]++;
pnt[a[1]].push_back(a[1]);
pnt[a[n]].push_back(a[n]);
sweep();
}
else{
get_table(1, n-1);
sum++;
occ[a[n]]++;
pnt[a[n]].push_back(a[n]);
sweep();
get_table(2, n);
sum++;
occ[a[1]]++;
pnt[a[1]].push_back(a[1]);
sweep();
}
for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
}
Compilation message
rope.cpp: In function 'int main()':
rope.cpp:55:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&m);
^
rope.cpp:57:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
3 ms |
41084 KB |
Output is correct |
4 |
Correct |
6 ms |
41084 KB |
Output is correct |
5 |
Correct |
6 ms |
41084 KB |
Output is correct |
6 |
Correct |
3 ms |
41084 KB |
Output is correct |
7 |
Correct |
0 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
9 ms |
41084 KB |
Output is correct |
11 |
Correct |
3 ms |
41084 KB |
Output is correct |
12 |
Correct |
3 ms |
41084 KB |
Output is correct |
13 |
Correct |
9 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
6 ms |
41084 KB |
Output is correct |
18 |
Correct |
3 ms |
41084 KB |
Output is correct |
19 |
Correct |
9 ms |
41084 KB |
Output is correct |
20 |
Correct |
3 ms |
41084 KB |
Output is correct |
21 |
Correct |
3 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
6 ms |
41084 KB |
Output is correct |
24 |
Correct |
9 ms |
41084 KB |
Output is correct |
25 |
Correct |
6 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
3 ms |
41084 KB |
Output is correct |
4 |
Correct |
6 ms |
41084 KB |
Output is correct |
5 |
Correct |
6 ms |
41084 KB |
Output is correct |
6 |
Correct |
3 ms |
41084 KB |
Output is correct |
7 |
Correct |
0 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
9 ms |
41084 KB |
Output is correct |
11 |
Correct |
3 ms |
41084 KB |
Output is correct |
12 |
Correct |
3 ms |
41084 KB |
Output is correct |
13 |
Correct |
9 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
6 ms |
41084 KB |
Output is correct |
18 |
Correct |
3 ms |
41084 KB |
Output is correct |
19 |
Correct |
9 ms |
41084 KB |
Output is correct |
20 |
Correct |
3 ms |
41084 KB |
Output is correct |
21 |
Correct |
3 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
6 ms |
41084 KB |
Output is correct |
24 |
Correct |
9 ms |
41084 KB |
Output is correct |
25 |
Correct |
6 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
49 ms |
44604 KB |
Output is correct |
28 |
Correct |
59 ms |
44248 KB |
Output is correct |
29 |
Correct |
53 ms |
44416 KB |
Output is correct |
30 |
Correct |
53 ms |
44508 KB |
Output is correct |
31 |
Correct |
56 ms |
44536 KB |
Output is correct |
32 |
Correct |
59 ms |
44244 KB |
Output is correct |
33 |
Correct |
43 ms |
44400 KB |
Output is correct |
34 |
Correct |
46 ms |
44508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
3 ms |
41084 KB |
Output is correct |
4 |
Correct |
6 ms |
41084 KB |
Output is correct |
5 |
Correct |
6 ms |
41084 KB |
Output is correct |
6 |
Correct |
3 ms |
41084 KB |
Output is correct |
7 |
Correct |
0 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
9 ms |
41084 KB |
Output is correct |
11 |
Correct |
3 ms |
41084 KB |
Output is correct |
12 |
Correct |
3 ms |
41084 KB |
Output is correct |
13 |
Correct |
9 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
6 ms |
41084 KB |
Output is correct |
18 |
Correct |
3 ms |
41084 KB |
Output is correct |
19 |
Correct |
9 ms |
41084 KB |
Output is correct |
20 |
Correct |
3 ms |
41084 KB |
Output is correct |
21 |
Correct |
3 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
6 ms |
41084 KB |
Output is correct |
24 |
Correct |
9 ms |
41084 KB |
Output is correct |
25 |
Correct |
6 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
49 ms |
44604 KB |
Output is correct |
28 |
Correct |
59 ms |
44248 KB |
Output is correct |
29 |
Correct |
53 ms |
44416 KB |
Output is correct |
30 |
Correct |
53 ms |
44508 KB |
Output is correct |
31 |
Correct |
56 ms |
44536 KB |
Output is correct |
32 |
Correct |
59 ms |
44244 KB |
Output is correct |
33 |
Correct |
43 ms |
44400 KB |
Output is correct |
34 |
Correct |
46 ms |
44508 KB |
Output is correct |
35 |
Correct |
46 ms |
44300 KB |
Output is correct |
36 |
Correct |
49 ms |
44320 KB |
Output is correct |
37 |
Correct |
56 ms |
44252 KB |
Output is correct |
38 |
Correct |
63 ms |
44296 KB |
Output is correct |
39 |
Correct |
49 ms |
44300 KB |
Output is correct |
40 |
Correct |
49 ms |
44472 KB |
Output is correct |
41 |
Correct |
43 ms |
44480 KB |
Output is correct |
42 |
Correct |
56 ms |
44428 KB |
Output is correct |
43 |
Correct |
53 ms |
44492 KB |
Output is correct |
44 |
Correct |
49 ms |
44456 KB |
Output is correct |
45 |
Correct |
43 ms |
44468 KB |
Output is correct |
46 |
Correct |
53 ms |
44420 KB |
Output is correct |
47 |
Correct |
59 ms |
44480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
3 ms |
41084 KB |
Output is correct |
4 |
Correct |
6 ms |
41084 KB |
Output is correct |
5 |
Correct |
6 ms |
41084 KB |
Output is correct |
6 |
Correct |
3 ms |
41084 KB |
Output is correct |
7 |
Correct |
0 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
9 ms |
41084 KB |
Output is correct |
11 |
Correct |
3 ms |
41084 KB |
Output is correct |
12 |
Correct |
3 ms |
41084 KB |
Output is correct |
13 |
Correct |
9 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
6 ms |
41084 KB |
Output is correct |
18 |
Correct |
3 ms |
41084 KB |
Output is correct |
19 |
Correct |
9 ms |
41084 KB |
Output is correct |
20 |
Correct |
3 ms |
41084 KB |
Output is correct |
21 |
Correct |
3 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
6 ms |
41084 KB |
Output is correct |
24 |
Correct |
9 ms |
41084 KB |
Output is correct |
25 |
Correct |
6 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
49 ms |
44604 KB |
Output is correct |
28 |
Correct |
59 ms |
44248 KB |
Output is correct |
29 |
Correct |
53 ms |
44416 KB |
Output is correct |
30 |
Correct |
53 ms |
44508 KB |
Output is correct |
31 |
Correct |
56 ms |
44536 KB |
Output is correct |
32 |
Correct |
59 ms |
44244 KB |
Output is correct |
33 |
Correct |
43 ms |
44400 KB |
Output is correct |
34 |
Correct |
46 ms |
44508 KB |
Output is correct |
35 |
Correct |
46 ms |
44300 KB |
Output is correct |
36 |
Correct |
49 ms |
44320 KB |
Output is correct |
37 |
Correct |
56 ms |
44252 KB |
Output is correct |
38 |
Correct |
63 ms |
44296 KB |
Output is correct |
39 |
Correct |
49 ms |
44300 KB |
Output is correct |
40 |
Correct |
49 ms |
44472 KB |
Output is correct |
41 |
Correct |
43 ms |
44480 KB |
Output is correct |
42 |
Correct |
56 ms |
44428 KB |
Output is correct |
43 |
Correct |
53 ms |
44492 KB |
Output is correct |
44 |
Correct |
49 ms |
44456 KB |
Output is correct |
45 |
Correct |
43 ms |
44468 KB |
Output is correct |
46 |
Correct |
53 ms |
44420 KB |
Output is correct |
47 |
Correct |
59 ms |
44480 KB |
Output is correct |
48 |
Correct |
549 ms |
70680 KB |
Output is correct |
49 |
Correct |
559 ms |
70652 KB |
Output is correct |
50 |
Correct |
543 ms |
70648 KB |
Output is correct |
51 |
Correct |
559 ms |
70628 KB |
Output is correct |
52 |
Correct |
516 ms |
68852 KB |
Output is correct |
53 |
Correct |
536 ms |
69108 KB |
Output is correct |
54 |
Correct |
499 ms |
67088 KB |
Output is correct |
55 |
Correct |
506 ms |
66760 KB |
Output is correct |
56 |
Correct |
516 ms |
66152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
41084 KB |
Output is correct |
2 |
Correct |
9 ms |
41084 KB |
Output is correct |
3 |
Correct |
3 ms |
41084 KB |
Output is correct |
4 |
Correct |
6 ms |
41084 KB |
Output is correct |
5 |
Correct |
6 ms |
41084 KB |
Output is correct |
6 |
Correct |
3 ms |
41084 KB |
Output is correct |
7 |
Correct |
0 ms |
41084 KB |
Output is correct |
8 |
Correct |
3 ms |
41084 KB |
Output is correct |
9 |
Correct |
6 ms |
41084 KB |
Output is correct |
10 |
Correct |
9 ms |
41084 KB |
Output is correct |
11 |
Correct |
3 ms |
41084 KB |
Output is correct |
12 |
Correct |
3 ms |
41084 KB |
Output is correct |
13 |
Correct |
9 ms |
41084 KB |
Output is correct |
14 |
Correct |
6 ms |
41084 KB |
Output is correct |
15 |
Correct |
3 ms |
41084 KB |
Output is correct |
16 |
Correct |
6 ms |
41084 KB |
Output is correct |
17 |
Correct |
6 ms |
41084 KB |
Output is correct |
18 |
Correct |
3 ms |
41084 KB |
Output is correct |
19 |
Correct |
9 ms |
41084 KB |
Output is correct |
20 |
Correct |
3 ms |
41084 KB |
Output is correct |
21 |
Correct |
3 ms |
41084 KB |
Output is correct |
22 |
Correct |
6 ms |
41084 KB |
Output is correct |
23 |
Correct |
6 ms |
41084 KB |
Output is correct |
24 |
Correct |
9 ms |
41084 KB |
Output is correct |
25 |
Correct |
6 ms |
41084 KB |
Output is correct |
26 |
Correct |
6 ms |
41084 KB |
Output is correct |
27 |
Correct |
49 ms |
44604 KB |
Output is correct |
28 |
Correct |
59 ms |
44248 KB |
Output is correct |
29 |
Correct |
53 ms |
44416 KB |
Output is correct |
30 |
Correct |
53 ms |
44508 KB |
Output is correct |
31 |
Correct |
56 ms |
44536 KB |
Output is correct |
32 |
Correct |
59 ms |
44244 KB |
Output is correct |
33 |
Correct |
43 ms |
44400 KB |
Output is correct |
34 |
Correct |
46 ms |
44508 KB |
Output is correct |
35 |
Correct |
46 ms |
44300 KB |
Output is correct |
36 |
Correct |
49 ms |
44320 KB |
Output is correct |
37 |
Correct |
56 ms |
44252 KB |
Output is correct |
38 |
Correct |
63 ms |
44296 KB |
Output is correct |
39 |
Correct |
49 ms |
44300 KB |
Output is correct |
40 |
Correct |
49 ms |
44472 KB |
Output is correct |
41 |
Correct |
43 ms |
44480 KB |
Output is correct |
42 |
Correct |
56 ms |
44428 KB |
Output is correct |
43 |
Correct |
53 ms |
44492 KB |
Output is correct |
44 |
Correct |
49 ms |
44456 KB |
Output is correct |
45 |
Correct |
43 ms |
44468 KB |
Output is correct |
46 |
Correct |
53 ms |
44420 KB |
Output is correct |
47 |
Correct |
59 ms |
44480 KB |
Output is correct |
48 |
Correct |
549 ms |
70680 KB |
Output is correct |
49 |
Correct |
559 ms |
70652 KB |
Output is correct |
50 |
Correct |
543 ms |
70648 KB |
Output is correct |
51 |
Correct |
559 ms |
70628 KB |
Output is correct |
52 |
Correct |
516 ms |
68852 KB |
Output is correct |
53 |
Correct |
536 ms |
69108 KB |
Output is correct |
54 |
Correct |
499 ms |
67088 KB |
Output is correct |
55 |
Correct |
506 ms |
66760 KB |
Output is correct |
56 |
Correct |
516 ms |
66152 KB |
Output is correct |
57 |
Incorrect |
139 ms |
41084 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |