# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535575 |
2022-03-10T14:06:14 Z |
amunduzbaev |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
104208 KB |
#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 1e6 + 5;
int a[N], res[N], cc[N];
map<int, int> edges[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
a[i]--;
}
{
memset(cc, 0, sizeof cc);
for(int i=1;i+1<n;i+=2){
if(a[i] != a[i+1]){
edges[a[i]][a[i+1]]++;
edges[a[i+1]][a[i]]++;
}
}
multiset<int> ss;
for(int i=0;i<n;i++){
cc[a[i]]++;
}
for(int i=0;i<m;i++) ss.insert(cc[i]);
for(int i=0;i<m;i++){
int rr = 0;
ss.erase(ss.find(cc[i]));
for(auto x : edges[i]){
ss.erase(ss.find(cc[x.first]));
rr = max(rr, cc[x.first] - x.second);
//~ cout<<i<<" "<<x.first<<" "<<cc[x.first]<<" "<<x.second<<"\n";
}
if(!ss.empty()) rr = max(rr, *ss.rbegin());
res[i] = max(res[i], rr + cc[i]);
for(auto x : edges[i]){
ss.insert(cc[x.first]);
}
ss.insert(cc[i]);
edges[i].clear();
}
}
{
memset(cc, 0, sizeof cc);
for(int i=0;i+1<n;i+=2){
if(a[i] != a[i+1]){
edges[a[i]][a[i+1]]++;
edges[a[i+1]][a[i]]++;
}
}
multiset<int> ss;
for(int i=0;i<n;i++){
cc[a[i]]++;
}
for(int i=0;i<m;i++) ss.insert(cc[i]);
for(int i=0;i<m;i++){
int rr = 0;
ss.erase(ss.find(cc[i]));
for(auto x : edges[i]){
ss.erase(ss.find(cc[x.first]));
rr = max(rr, cc[x.first] - x.second);
//~ cout<<i<<" "<<x.first<<" "<<cc[x.first]<<" "<<x.second<<"\n";
}
if(!ss.empty()) rr = max(rr, *ss.rbegin());
res[i] = max(res[i], rr + cc[i]);
for(auto x : edges[i]){
ss.insert(cc[x.first]);
}
ss.insert(cc[i]);
edges[i].clear();
}
}
for(int i=0;i<m;i++) cout<<n - res[i]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
51156 KB |
Output is correct |
2 |
Correct |
28 ms |
51140 KB |
Output is correct |
3 |
Correct |
26 ms |
51112 KB |
Output is correct |
4 |
Correct |
25 ms |
51108 KB |
Output is correct |
5 |
Correct |
25 ms |
51156 KB |
Output is correct |
6 |
Correct |
26 ms |
51128 KB |
Output is correct |
7 |
Correct |
28 ms |
51148 KB |
Output is correct |
8 |
Correct |
33 ms |
51168 KB |
Output is correct |
9 |
Correct |
26 ms |
51144 KB |
Output is correct |
10 |
Correct |
33 ms |
51156 KB |
Output is correct |
11 |
Correct |
27 ms |
51120 KB |
Output is correct |
12 |
Correct |
24 ms |
51196 KB |
Output is correct |
13 |
Correct |
29 ms |
51164 KB |
Output is correct |
14 |
Correct |
25 ms |
51156 KB |
Output is correct |
15 |
Correct |
27 ms |
51224 KB |
Output is correct |
16 |
Correct |
25 ms |
51164 KB |
Output is correct |
17 |
Correct |
27 ms |
51156 KB |
Output is correct |
18 |
Correct |
28 ms |
51076 KB |
Output is correct |
19 |
Correct |
28 ms |
51180 KB |
Output is correct |
20 |
Correct |
28 ms |
51108 KB |
Output is correct |
21 |
Correct |
25 ms |
51144 KB |
Output is correct |
22 |
Correct |
26 ms |
51124 KB |
Output is correct |
23 |
Correct |
28 ms |
51136 KB |
Output is correct |
24 |
Correct |
27 ms |
51108 KB |
Output is correct |
25 |
Correct |
26 ms |
51148 KB |
Output is correct |
26 |
Correct |
26 ms |
51116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
51156 KB |
Output is correct |
2 |
Correct |
28 ms |
51140 KB |
Output is correct |
3 |
Correct |
26 ms |
51112 KB |
Output is correct |
4 |
Correct |
25 ms |
51108 KB |
Output is correct |
5 |
Correct |
25 ms |
51156 KB |
Output is correct |
6 |
Correct |
26 ms |
51128 KB |
Output is correct |
7 |
Correct |
28 ms |
51148 KB |
Output is correct |
8 |
Correct |
33 ms |
51168 KB |
Output is correct |
9 |
Correct |
26 ms |
51144 KB |
Output is correct |
10 |
Correct |
33 ms |
51156 KB |
Output is correct |
11 |
Correct |
27 ms |
51120 KB |
Output is correct |
12 |
Correct |
24 ms |
51196 KB |
Output is correct |
13 |
Correct |
29 ms |
51164 KB |
Output is correct |
14 |
Correct |
25 ms |
51156 KB |
Output is correct |
15 |
Correct |
27 ms |
51224 KB |
Output is correct |
16 |
Correct |
25 ms |
51164 KB |
Output is correct |
17 |
Correct |
27 ms |
51156 KB |
Output is correct |
18 |
Correct |
28 ms |
51076 KB |
Output is correct |
19 |
Correct |
28 ms |
51180 KB |
Output is correct |
20 |
Correct |
28 ms |
51108 KB |
Output is correct |
21 |
Correct |
25 ms |
51144 KB |
Output is correct |
22 |
Correct |
26 ms |
51124 KB |
Output is correct |
23 |
Correct |
28 ms |
51136 KB |
Output is correct |
24 |
Correct |
27 ms |
51108 KB |
Output is correct |
25 |
Correct |
26 ms |
51148 KB |
Output is correct |
26 |
Correct |
26 ms |
51116 KB |
Output is correct |
27 |
Correct |
39 ms |
51684 KB |
Output is correct |
28 |
Correct |
46 ms |
51664 KB |
Output is correct |
29 |
Correct |
35 ms |
51712 KB |
Output is correct |
30 |
Correct |
34 ms |
51704 KB |
Output is correct |
31 |
Correct |
42 ms |
51808 KB |
Output is correct |
32 |
Correct |
34 ms |
51792 KB |
Output is correct |
33 |
Correct |
37 ms |
51796 KB |
Output is correct |
34 |
Correct |
43 ms |
51712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
51156 KB |
Output is correct |
2 |
Correct |
28 ms |
51140 KB |
Output is correct |
3 |
Correct |
26 ms |
51112 KB |
Output is correct |
4 |
Correct |
25 ms |
51108 KB |
Output is correct |
5 |
Correct |
25 ms |
51156 KB |
Output is correct |
6 |
Correct |
26 ms |
51128 KB |
Output is correct |
7 |
Correct |
28 ms |
51148 KB |
Output is correct |
8 |
Correct |
33 ms |
51168 KB |
Output is correct |
9 |
Correct |
26 ms |
51144 KB |
Output is correct |
10 |
Correct |
33 ms |
51156 KB |
Output is correct |
11 |
Correct |
27 ms |
51120 KB |
Output is correct |
12 |
Correct |
24 ms |
51196 KB |
Output is correct |
13 |
Correct |
29 ms |
51164 KB |
Output is correct |
14 |
Correct |
25 ms |
51156 KB |
Output is correct |
15 |
Correct |
27 ms |
51224 KB |
Output is correct |
16 |
Correct |
25 ms |
51164 KB |
Output is correct |
17 |
Correct |
27 ms |
51156 KB |
Output is correct |
18 |
Correct |
28 ms |
51076 KB |
Output is correct |
19 |
Correct |
28 ms |
51180 KB |
Output is correct |
20 |
Correct |
28 ms |
51108 KB |
Output is correct |
21 |
Correct |
25 ms |
51144 KB |
Output is correct |
22 |
Correct |
26 ms |
51124 KB |
Output is correct |
23 |
Correct |
28 ms |
51136 KB |
Output is correct |
24 |
Correct |
27 ms |
51108 KB |
Output is correct |
25 |
Correct |
26 ms |
51148 KB |
Output is correct |
26 |
Correct |
26 ms |
51116 KB |
Output is correct |
27 |
Correct |
39 ms |
51684 KB |
Output is correct |
28 |
Correct |
46 ms |
51664 KB |
Output is correct |
29 |
Correct |
35 ms |
51712 KB |
Output is correct |
30 |
Correct |
34 ms |
51704 KB |
Output is correct |
31 |
Correct |
42 ms |
51808 KB |
Output is correct |
32 |
Correct |
34 ms |
51792 KB |
Output is correct |
33 |
Correct |
37 ms |
51796 KB |
Output is correct |
34 |
Correct |
43 ms |
51712 KB |
Output is correct |
35 |
Correct |
147 ms |
55856 KB |
Output is correct |
36 |
Correct |
109 ms |
55752 KB |
Output is correct |
37 |
Correct |
125 ms |
55812 KB |
Output is correct |
38 |
Correct |
142 ms |
55828 KB |
Output is correct |
39 |
Correct |
114 ms |
55848 KB |
Output is correct |
40 |
Correct |
73 ms |
53924 KB |
Output is correct |
41 |
Correct |
82 ms |
54120 KB |
Output is correct |
42 |
Correct |
69 ms |
53544 KB |
Output is correct |
43 |
Correct |
66 ms |
53472 KB |
Output is correct |
44 |
Correct |
78 ms |
53976 KB |
Output is correct |
45 |
Correct |
75 ms |
54060 KB |
Output is correct |
46 |
Correct |
66 ms |
53544 KB |
Output is correct |
47 |
Correct |
75 ms |
53488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
51156 KB |
Output is correct |
2 |
Correct |
28 ms |
51140 KB |
Output is correct |
3 |
Correct |
26 ms |
51112 KB |
Output is correct |
4 |
Correct |
25 ms |
51108 KB |
Output is correct |
5 |
Correct |
25 ms |
51156 KB |
Output is correct |
6 |
Correct |
26 ms |
51128 KB |
Output is correct |
7 |
Correct |
28 ms |
51148 KB |
Output is correct |
8 |
Correct |
33 ms |
51168 KB |
Output is correct |
9 |
Correct |
26 ms |
51144 KB |
Output is correct |
10 |
Correct |
33 ms |
51156 KB |
Output is correct |
11 |
Correct |
27 ms |
51120 KB |
Output is correct |
12 |
Correct |
24 ms |
51196 KB |
Output is correct |
13 |
Correct |
29 ms |
51164 KB |
Output is correct |
14 |
Correct |
25 ms |
51156 KB |
Output is correct |
15 |
Correct |
27 ms |
51224 KB |
Output is correct |
16 |
Correct |
25 ms |
51164 KB |
Output is correct |
17 |
Correct |
27 ms |
51156 KB |
Output is correct |
18 |
Correct |
28 ms |
51076 KB |
Output is correct |
19 |
Correct |
28 ms |
51180 KB |
Output is correct |
20 |
Correct |
28 ms |
51108 KB |
Output is correct |
21 |
Correct |
25 ms |
51144 KB |
Output is correct |
22 |
Correct |
26 ms |
51124 KB |
Output is correct |
23 |
Correct |
28 ms |
51136 KB |
Output is correct |
24 |
Correct |
27 ms |
51108 KB |
Output is correct |
25 |
Correct |
26 ms |
51148 KB |
Output is correct |
26 |
Correct |
26 ms |
51116 KB |
Output is correct |
27 |
Correct |
39 ms |
51684 KB |
Output is correct |
28 |
Correct |
46 ms |
51664 KB |
Output is correct |
29 |
Correct |
35 ms |
51712 KB |
Output is correct |
30 |
Correct |
34 ms |
51704 KB |
Output is correct |
31 |
Correct |
42 ms |
51808 KB |
Output is correct |
32 |
Correct |
34 ms |
51792 KB |
Output is correct |
33 |
Correct |
37 ms |
51796 KB |
Output is correct |
34 |
Correct |
43 ms |
51712 KB |
Output is correct |
35 |
Correct |
147 ms |
55856 KB |
Output is correct |
36 |
Correct |
109 ms |
55752 KB |
Output is correct |
37 |
Correct |
125 ms |
55812 KB |
Output is correct |
38 |
Correct |
142 ms |
55828 KB |
Output is correct |
39 |
Correct |
114 ms |
55848 KB |
Output is correct |
40 |
Correct |
73 ms |
53924 KB |
Output is correct |
41 |
Correct |
82 ms |
54120 KB |
Output is correct |
42 |
Correct |
69 ms |
53544 KB |
Output is correct |
43 |
Correct |
66 ms |
53472 KB |
Output is correct |
44 |
Correct |
78 ms |
53976 KB |
Output is correct |
45 |
Correct |
75 ms |
54060 KB |
Output is correct |
46 |
Correct |
66 ms |
53544 KB |
Output is correct |
47 |
Correct |
75 ms |
53488 KB |
Output is correct |
48 |
Execution timed out |
2567 ms |
104208 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
51156 KB |
Output is correct |
2 |
Correct |
28 ms |
51140 KB |
Output is correct |
3 |
Correct |
26 ms |
51112 KB |
Output is correct |
4 |
Correct |
25 ms |
51108 KB |
Output is correct |
5 |
Correct |
25 ms |
51156 KB |
Output is correct |
6 |
Correct |
26 ms |
51128 KB |
Output is correct |
7 |
Correct |
28 ms |
51148 KB |
Output is correct |
8 |
Correct |
33 ms |
51168 KB |
Output is correct |
9 |
Correct |
26 ms |
51144 KB |
Output is correct |
10 |
Correct |
33 ms |
51156 KB |
Output is correct |
11 |
Correct |
27 ms |
51120 KB |
Output is correct |
12 |
Correct |
24 ms |
51196 KB |
Output is correct |
13 |
Correct |
29 ms |
51164 KB |
Output is correct |
14 |
Correct |
25 ms |
51156 KB |
Output is correct |
15 |
Correct |
27 ms |
51224 KB |
Output is correct |
16 |
Correct |
25 ms |
51164 KB |
Output is correct |
17 |
Correct |
27 ms |
51156 KB |
Output is correct |
18 |
Correct |
28 ms |
51076 KB |
Output is correct |
19 |
Correct |
28 ms |
51180 KB |
Output is correct |
20 |
Correct |
28 ms |
51108 KB |
Output is correct |
21 |
Correct |
25 ms |
51144 KB |
Output is correct |
22 |
Correct |
26 ms |
51124 KB |
Output is correct |
23 |
Correct |
28 ms |
51136 KB |
Output is correct |
24 |
Correct |
27 ms |
51108 KB |
Output is correct |
25 |
Correct |
26 ms |
51148 KB |
Output is correct |
26 |
Correct |
26 ms |
51116 KB |
Output is correct |
27 |
Correct |
39 ms |
51684 KB |
Output is correct |
28 |
Correct |
46 ms |
51664 KB |
Output is correct |
29 |
Correct |
35 ms |
51712 KB |
Output is correct |
30 |
Correct |
34 ms |
51704 KB |
Output is correct |
31 |
Correct |
42 ms |
51808 KB |
Output is correct |
32 |
Correct |
34 ms |
51792 KB |
Output is correct |
33 |
Correct |
37 ms |
51796 KB |
Output is correct |
34 |
Correct |
43 ms |
51712 KB |
Output is correct |
35 |
Correct |
147 ms |
55856 KB |
Output is correct |
36 |
Correct |
109 ms |
55752 KB |
Output is correct |
37 |
Correct |
125 ms |
55812 KB |
Output is correct |
38 |
Correct |
142 ms |
55828 KB |
Output is correct |
39 |
Correct |
114 ms |
55848 KB |
Output is correct |
40 |
Correct |
73 ms |
53924 KB |
Output is correct |
41 |
Correct |
82 ms |
54120 KB |
Output is correct |
42 |
Correct |
69 ms |
53544 KB |
Output is correct |
43 |
Correct |
66 ms |
53472 KB |
Output is correct |
44 |
Correct |
78 ms |
53976 KB |
Output is correct |
45 |
Correct |
75 ms |
54060 KB |
Output is correct |
46 |
Correct |
66 ms |
53544 KB |
Output is correct |
47 |
Correct |
75 ms |
53488 KB |
Output is correct |
48 |
Execution timed out |
2567 ms |
104208 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |