# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670487 |
2022-12-09T08:58:38 Z |
Mahdi |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
119132 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=1e6+5;
int n, m, c[N], cnt[N], ans[N];
vector<int>v[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i){
cin>>c[i];
v[c[i]].push_back(i);
++cnt[c[i]];
}
if(m==1){
cout<<0<<'\n';
return 0;
}
set<pii>s;
for(int i=1;i<=m;++i)
s.insert({cnt[i], i});
for(int i=1;i<=m;++i){
s.erase({cnt[i], i});
vector<int>w;
for(int u: v[i]){
int z=u+((u&1) ? -1 : 1);
if(z>0 && z<=n && c[z]!=i){
z=c[z];
s.erase({cnt[z], z});
w.push_back(z);
--cnt[z];
s.insert({cnt[z], z});
}
}
auto it=s.end();
--it;
ans[i]=cnt[i]+it->F;
for(int u: w){
s.erase({cnt[u], u});
++cnt[u];
s.insert({cnt[u], u});
}
w.clear();
for(int u: v[i]){
int z=u+((u&1) ? 1 : -1);
if(z>0 && z<=n && c[z]!=i){
z=c[z];
s.erase({cnt[z], z});
w.push_back(z);
--cnt[z];
s.insert({cnt[z], z});
}
}
it=s.end();
--it;
ans[i]=max(ans[i], cnt[i]+it->F);
for(int u: w){
s.erase({cnt[u], u});
++cnt[u];
s.insert({cnt[u], u});
}
s.insert({cnt[i], i});
}
for(int i=1;i<=m;++i)
cout<<n-ans[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23820 KB |
Output is correct |
3 |
Correct |
12 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23696 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23736 KB |
Output is correct |
7 |
Correct |
12 ms |
23780 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23828 KB |
Output is correct |
12 |
Correct |
14 ms |
23792 KB |
Output is correct |
13 |
Correct |
12 ms |
23832 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
12 ms |
23744 KB |
Output is correct |
17 |
Correct |
12 ms |
23752 KB |
Output is correct |
18 |
Correct |
12 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23772 KB |
Output is correct |
20 |
Correct |
12 ms |
23812 KB |
Output is correct |
21 |
Correct |
14 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23824 KB |
Output is correct |
24 |
Correct |
13 ms |
23880 KB |
Output is correct |
25 |
Correct |
14 ms |
23812 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23820 KB |
Output is correct |
3 |
Correct |
12 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23696 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23736 KB |
Output is correct |
7 |
Correct |
12 ms |
23780 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23828 KB |
Output is correct |
12 |
Correct |
14 ms |
23792 KB |
Output is correct |
13 |
Correct |
12 ms |
23832 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
12 ms |
23744 KB |
Output is correct |
17 |
Correct |
12 ms |
23752 KB |
Output is correct |
18 |
Correct |
12 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23772 KB |
Output is correct |
20 |
Correct |
12 ms |
23812 KB |
Output is correct |
21 |
Correct |
14 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23824 KB |
Output is correct |
24 |
Correct |
13 ms |
23880 KB |
Output is correct |
25 |
Correct |
14 ms |
23812 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
48 ms |
25104 KB |
Output is correct |
28 |
Correct |
36 ms |
25076 KB |
Output is correct |
29 |
Correct |
48 ms |
24976 KB |
Output is correct |
30 |
Correct |
38 ms |
25044 KB |
Output is correct |
31 |
Correct |
48 ms |
25088 KB |
Output is correct |
32 |
Correct |
37 ms |
25112 KB |
Output is correct |
33 |
Correct |
49 ms |
25028 KB |
Output is correct |
34 |
Correct |
39 ms |
25044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23820 KB |
Output is correct |
3 |
Correct |
12 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23696 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23736 KB |
Output is correct |
7 |
Correct |
12 ms |
23780 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23828 KB |
Output is correct |
12 |
Correct |
14 ms |
23792 KB |
Output is correct |
13 |
Correct |
12 ms |
23832 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
12 ms |
23744 KB |
Output is correct |
17 |
Correct |
12 ms |
23752 KB |
Output is correct |
18 |
Correct |
12 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23772 KB |
Output is correct |
20 |
Correct |
12 ms |
23812 KB |
Output is correct |
21 |
Correct |
14 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23824 KB |
Output is correct |
24 |
Correct |
13 ms |
23880 KB |
Output is correct |
25 |
Correct |
14 ms |
23812 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
48 ms |
25104 KB |
Output is correct |
28 |
Correct |
36 ms |
25076 KB |
Output is correct |
29 |
Correct |
48 ms |
24976 KB |
Output is correct |
30 |
Correct |
38 ms |
25044 KB |
Output is correct |
31 |
Correct |
48 ms |
25088 KB |
Output is correct |
32 |
Correct |
37 ms |
25112 KB |
Output is correct |
33 |
Correct |
49 ms |
25028 KB |
Output is correct |
34 |
Correct |
39 ms |
25044 KB |
Output is correct |
35 |
Correct |
117 ms |
25172 KB |
Output is correct |
36 |
Correct |
113 ms |
25156 KB |
Output is correct |
37 |
Correct |
118 ms |
25220 KB |
Output is correct |
38 |
Correct |
114 ms |
25152 KB |
Output is correct |
39 |
Correct |
113 ms |
25080 KB |
Output is correct |
40 |
Correct |
102 ms |
25240 KB |
Output is correct |
41 |
Correct |
102 ms |
25244 KB |
Output is correct |
42 |
Correct |
101 ms |
25420 KB |
Output is correct |
43 |
Correct |
98 ms |
25232 KB |
Output is correct |
44 |
Correct |
106 ms |
25240 KB |
Output is correct |
45 |
Correct |
103 ms |
25244 KB |
Output is correct |
46 |
Correct |
101 ms |
25208 KB |
Output is correct |
47 |
Correct |
104 ms |
25172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23820 KB |
Output is correct |
3 |
Correct |
12 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23696 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23736 KB |
Output is correct |
7 |
Correct |
12 ms |
23780 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23828 KB |
Output is correct |
12 |
Correct |
14 ms |
23792 KB |
Output is correct |
13 |
Correct |
12 ms |
23832 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
12 ms |
23744 KB |
Output is correct |
17 |
Correct |
12 ms |
23752 KB |
Output is correct |
18 |
Correct |
12 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23772 KB |
Output is correct |
20 |
Correct |
12 ms |
23812 KB |
Output is correct |
21 |
Correct |
14 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23824 KB |
Output is correct |
24 |
Correct |
13 ms |
23880 KB |
Output is correct |
25 |
Correct |
14 ms |
23812 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
48 ms |
25104 KB |
Output is correct |
28 |
Correct |
36 ms |
25076 KB |
Output is correct |
29 |
Correct |
48 ms |
24976 KB |
Output is correct |
30 |
Correct |
38 ms |
25044 KB |
Output is correct |
31 |
Correct |
48 ms |
25088 KB |
Output is correct |
32 |
Correct |
37 ms |
25112 KB |
Output is correct |
33 |
Correct |
49 ms |
25028 KB |
Output is correct |
34 |
Correct |
39 ms |
25044 KB |
Output is correct |
35 |
Correct |
117 ms |
25172 KB |
Output is correct |
36 |
Correct |
113 ms |
25156 KB |
Output is correct |
37 |
Correct |
118 ms |
25220 KB |
Output is correct |
38 |
Correct |
114 ms |
25152 KB |
Output is correct |
39 |
Correct |
113 ms |
25080 KB |
Output is correct |
40 |
Correct |
102 ms |
25240 KB |
Output is correct |
41 |
Correct |
102 ms |
25244 KB |
Output is correct |
42 |
Correct |
101 ms |
25420 KB |
Output is correct |
43 |
Correct |
98 ms |
25232 KB |
Output is correct |
44 |
Correct |
106 ms |
25240 KB |
Output is correct |
45 |
Correct |
103 ms |
25244 KB |
Output is correct |
46 |
Correct |
101 ms |
25208 KB |
Output is correct |
47 |
Correct |
104 ms |
25172 KB |
Output is correct |
48 |
Correct |
1367 ms |
38920 KB |
Output is correct |
49 |
Correct |
1351 ms |
39036 KB |
Output is correct |
50 |
Correct |
1337 ms |
38988 KB |
Output is correct |
51 |
Correct |
1228 ms |
38512 KB |
Output is correct |
52 |
Correct |
1164 ms |
37336 KB |
Output is correct |
53 |
Correct |
1130 ms |
38140 KB |
Output is correct |
54 |
Correct |
1085 ms |
37208 KB |
Output is correct |
55 |
Correct |
1079 ms |
37156 KB |
Output is correct |
56 |
Correct |
1041 ms |
36740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23820 KB |
Output is correct |
3 |
Correct |
12 ms |
23776 KB |
Output is correct |
4 |
Correct |
12 ms |
23696 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23736 KB |
Output is correct |
7 |
Correct |
12 ms |
23780 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23824 KB |
Output is correct |
11 |
Correct |
12 ms |
23828 KB |
Output is correct |
12 |
Correct |
14 ms |
23792 KB |
Output is correct |
13 |
Correct |
12 ms |
23832 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23792 KB |
Output is correct |
16 |
Correct |
12 ms |
23744 KB |
Output is correct |
17 |
Correct |
12 ms |
23752 KB |
Output is correct |
18 |
Correct |
12 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23772 KB |
Output is correct |
20 |
Correct |
12 ms |
23812 KB |
Output is correct |
21 |
Correct |
14 ms |
23764 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23824 KB |
Output is correct |
24 |
Correct |
13 ms |
23880 KB |
Output is correct |
25 |
Correct |
14 ms |
23812 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
48 ms |
25104 KB |
Output is correct |
28 |
Correct |
36 ms |
25076 KB |
Output is correct |
29 |
Correct |
48 ms |
24976 KB |
Output is correct |
30 |
Correct |
38 ms |
25044 KB |
Output is correct |
31 |
Correct |
48 ms |
25088 KB |
Output is correct |
32 |
Correct |
37 ms |
25112 KB |
Output is correct |
33 |
Correct |
49 ms |
25028 KB |
Output is correct |
34 |
Correct |
39 ms |
25044 KB |
Output is correct |
35 |
Correct |
117 ms |
25172 KB |
Output is correct |
36 |
Correct |
113 ms |
25156 KB |
Output is correct |
37 |
Correct |
118 ms |
25220 KB |
Output is correct |
38 |
Correct |
114 ms |
25152 KB |
Output is correct |
39 |
Correct |
113 ms |
25080 KB |
Output is correct |
40 |
Correct |
102 ms |
25240 KB |
Output is correct |
41 |
Correct |
102 ms |
25244 KB |
Output is correct |
42 |
Correct |
101 ms |
25420 KB |
Output is correct |
43 |
Correct |
98 ms |
25232 KB |
Output is correct |
44 |
Correct |
106 ms |
25240 KB |
Output is correct |
45 |
Correct |
103 ms |
25244 KB |
Output is correct |
46 |
Correct |
101 ms |
25208 KB |
Output is correct |
47 |
Correct |
104 ms |
25172 KB |
Output is correct |
48 |
Correct |
1367 ms |
38920 KB |
Output is correct |
49 |
Correct |
1351 ms |
39036 KB |
Output is correct |
50 |
Correct |
1337 ms |
38988 KB |
Output is correct |
51 |
Correct |
1228 ms |
38512 KB |
Output is correct |
52 |
Correct |
1164 ms |
37336 KB |
Output is correct |
53 |
Correct |
1130 ms |
38140 KB |
Output is correct |
54 |
Correct |
1085 ms |
37208 KB |
Output is correct |
55 |
Correct |
1079 ms |
37156 KB |
Output is correct |
56 |
Correct |
1041 ms |
36740 KB |
Output is correct |
57 |
Execution timed out |
2564 ms |
119132 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |