# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1001011 |
2024-06-18T12:45:25 Z |
Otalp |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
251856 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
map<pii, int> dp[2];
int cnt[1001000];
int a[1001000];
vector<int> d[1000100];
void solve(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>a[i];
cnt[a[i]] ++;
}
vector<pii> g;
for(int i=1; i<=m; i++){
g.pb({cnt[i], i});
}
sort(g.begin(), g.end());
int h[2]={0, 0};
for(int i=1; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
dp[1][{l, r}] ++;
dp[1][{r, l}] ++;
h[1] ++;
d[l].pb(r);
d[r].pb(l);
}
for(int i=2; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
dp[0][{l, r}] ++;
dp[0][{r, l}] ++;
h[0] ++;
d[l].pb(r);
d[r].pb(l);
}
for(int i=1; i<=m; i++){
int ans = n - cnt[i];
int ls = g.size() - 1;
map<int, int> us;
us[i] = 1;
for(int j: d[i]){
if(j == i) continue;
for(int k=0; k<2; k++){
ans = min(ans, n-cnt[i]-cnt[j]+dp[k][{i, j}]);
}
us[j] = 1;
}
while(us[g[ls].ss]) ls--;
if(ls >= 0) ans = min(ans, n - cnt[i] - g[ls].ff);
cout<<ans<<'\n';
}
}
signed main(){
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
4 ms |
23900 KB |
Output is correct |
3 |
Correct |
6 ms |
23928 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23708 KB |
Output is correct |
6 |
Correct |
5 ms |
23900 KB |
Output is correct |
7 |
Correct |
5 ms |
23900 KB |
Output is correct |
8 |
Correct |
5 ms |
23936 KB |
Output is correct |
9 |
Correct |
6 ms |
23900 KB |
Output is correct |
10 |
Correct |
6 ms |
23900 KB |
Output is correct |
11 |
Correct |
5 ms |
23904 KB |
Output is correct |
12 |
Correct |
4 ms |
23900 KB |
Output is correct |
13 |
Correct |
6 ms |
23928 KB |
Output is correct |
14 |
Correct |
5 ms |
23900 KB |
Output is correct |
15 |
Correct |
6 ms |
23900 KB |
Output is correct |
16 |
Correct |
5 ms |
23900 KB |
Output is correct |
17 |
Correct |
5 ms |
23928 KB |
Output is correct |
18 |
Correct |
6 ms |
23900 KB |
Output is correct |
19 |
Correct |
5 ms |
23900 KB |
Output is correct |
20 |
Correct |
7 ms |
23928 KB |
Output is correct |
21 |
Correct |
5 ms |
23936 KB |
Output is correct |
22 |
Correct |
7 ms |
23900 KB |
Output is correct |
23 |
Correct |
6 ms |
23900 KB |
Output is correct |
24 |
Correct |
5 ms |
23900 KB |
Output is correct |
25 |
Correct |
4 ms |
23932 KB |
Output is correct |
26 |
Correct |
5 ms |
23932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
4 ms |
23900 KB |
Output is correct |
3 |
Correct |
6 ms |
23928 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23708 KB |
Output is correct |
6 |
Correct |
5 ms |
23900 KB |
Output is correct |
7 |
Correct |
5 ms |
23900 KB |
Output is correct |
8 |
Correct |
5 ms |
23936 KB |
Output is correct |
9 |
Correct |
6 ms |
23900 KB |
Output is correct |
10 |
Correct |
6 ms |
23900 KB |
Output is correct |
11 |
Correct |
5 ms |
23904 KB |
Output is correct |
12 |
Correct |
4 ms |
23900 KB |
Output is correct |
13 |
Correct |
6 ms |
23928 KB |
Output is correct |
14 |
Correct |
5 ms |
23900 KB |
Output is correct |
15 |
Correct |
6 ms |
23900 KB |
Output is correct |
16 |
Correct |
5 ms |
23900 KB |
Output is correct |
17 |
Correct |
5 ms |
23928 KB |
Output is correct |
18 |
Correct |
6 ms |
23900 KB |
Output is correct |
19 |
Correct |
5 ms |
23900 KB |
Output is correct |
20 |
Correct |
7 ms |
23928 KB |
Output is correct |
21 |
Correct |
5 ms |
23936 KB |
Output is correct |
22 |
Correct |
7 ms |
23900 KB |
Output is correct |
23 |
Correct |
6 ms |
23900 KB |
Output is correct |
24 |
Correct |
5 ms |
23900 KB |
Output is correct |
25 |
Correct |
4 ms |
23932 KB |
Output is correct |
26 |
Correct |
5 ms |
23932 KB |
Output is correct |
27 |
Correct |
32 ms |
25688 KB |
Output is correct |
28 |
Correct |
20 ms |
25436 KB |
Output is correct |
29 |
Correct |
25 ms |
25432 KB |
Output is correct |
30 |
Correct |
22 ms |
25548 KB |
Output is correct |
31 |
Correct |
28 ms |
25756 KB |
Output is correct |
32 |
Correct |
22 ms |
25368 KB |
Output is correct |
33 |
Correct |
29 ms |
25464 KB |
Output is correct |
34 |
Correct |
22 ms |
25480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
4 ms |
23900 KB |
Output is correct |
3 |
Correct |
6 ms |
23928 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23708 KB |
Output is correct |
6 |
Correct |
5 ms |
23900 KB |
Output is correct |
7 |
Correct |
5 ms |
23900 KB |
Output is correct |
8 |
Correct |
5 ms |
23936 KB |
Output is correct |
9 |
Correct |
6 ms |
23900 KB |
Output is correct |
10 |
Correct |
6 ms |
23900 KB |
Output is correct |
11 |
Correct |
5 ms |
23904 KB |
Output is correct |
12 |
Correct |
4 ms |
23900 KB |
Output is correct |
13 |
Correct |
6 ms |
23928 KB |
Output is correct |
14 |
Correct |
5 ms |
23900 KB |
Output is correct |
15 |
Correct |
6 ms |
23900 KB |
Output is correct |
16 |
Correct |
5 ms |
23900 KB |
Output is correct |
17 |
Correct |
5 ms |
23928 KB |
Output is correct |
18 |
Correct |
6 ms |
23900 KB |
Output is correct |
19 |
Correct |
5 ms |
23900 KB |
Output is correct |
20 |
Correct |
7 ms |
23928 KB |
Output is correct |
21 |
Correct |
5 ms |
23936 KB |
Output is correct |
22 |
Correct |
7 ms |
23900 KB |
Output is correct |
23 |
Correct |
6 ms |
23900 KB |
Output is correct |
24 |
Correct |
5 ms |
23900 KB |
Output is correct |
25 |
Correct |
4 ms |
23932 KB |
Output is correct |
26 |
Correct |
5 ms |
23932 KB |
Output is correct |
27 |
Correct |
32 ms |
25688 KB |
Output is correct |
28 |
Correct |
20 ms |
25436 KB |
Output is correct |
29 |
Correct |
25 ms |
25432 KB |
Output is correct |
30 |
Correct |
22 ms |
25548 KB |
Output is correct |
31 |
Correct |
28 ms |
25756 KB |
Output is correct |
32 |
Correct |
22 ms |
25368 KB |
Output is correct |
33 |
Correct |
29 ms |
25464 KB |
Output is correct |
34 |
Correct |
22 ms |
25480 KB |
Output is correct |
35 |
Correct |
170 ms |
42920 KB |
Output is correct |
36 |
Correct |
183 ms |
42836 KB |
Output is correct |
37 |
Correct |
170 ms |
42284 KB |
Output is correct |
38 |
Correct |
167 ms |
42648 KB |
Output is correct |
39 |
Correct |
161 ms |
42832 KB |
Output is correct |
40 |
Correct |
89 ms |
34428 KB |
Output is correct |
41 |
Correct |
87 ms |
34408 KB |
Output is correct |
42 |
Correct |
74 ms |
31940 KB |
Output is correct |
43 |
Correct |
74 ms |
30944 KB |
Output is correct |
44 |
Correct |
99 ms |
34900 KB |
Output is correct |
45 |
Correct |
86 ms |
34732 KB |
Output is correct |
46 |
Correct |
77 ms |
32272 KB |
Output is correct |
47 |
Correct |
74 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
4 ms |
23900 KB |
Output is correct |
3 |
Correct |
6 ms |
23928 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23708 KB |
Output is correct |
6 |
Correct |
5 ms |
23900 KB |
Output is correct |
7 |
Correct |
5 ms |
23900 KB |
Output is correct |
8 |
Correct |
5 ms |
23936 KB |
Output is correct |
9 |
Correct |
6 ms |
23900 KB |
Output is correct |
10 |
Correct |
6 ms |
23900 KB |
Output is correct |
11 |
Correct |
5 ms |
23904 KB |
Output is correct |
12 |
Correct |
4 ms |
23900 KB |
Output is correct |
13 |
Correct |
6 ms |
23928 KB |
Output is correct |
14 |
Correct |
5 ms |
23900 KB |
Output is correct |
15 |
Correct |
6 ms |
23900 KB |
Output is correct |
16 |
Correct |
5 ms |
23900 KB |
Output is correct |
17 |
Correct |
5 ms |
23928 KB |
Output is correct |
18 |
Correct |
6 ms |
23900 KB |
Output is correct |
19 |
Correct |
5 ms |
23900 KB |
Output is correct |
20 |
Correct |
7 ms |
23928 KB |
Output is correct |
21 |
Correct |
5 ms |
23936 KB |
Output is correct |
22 |
Correct |
7 ms |
23900 KB |
Output is correct |
23 |
Correct |
6 ms |
23900 KB |
Output is correct |
24 |
Correct |
5 ms |
23900 KB |
Output is correct |
25 |
Correct |
4 ms |
23932 KB |
Output is correct |
26 |
Correct |
5 ms |
23932 KB |
Output is correct |
27 |
Correct |
32 ms |
25688 KB |
Output is correct |
28 |
Correct |
20 ms |
25436 KB |
Output is correct |
29 |
Correct |
25 ms |
25432 KB |
Output is correct |
30 |
Correct |
22 ms |
25548 KB |
Output is correct |
31 |
Correct |
28 ms |
25756 KB |
Output is correct |
32 |
Correct |
22 ms |
25368 KB |
Output is correct |
33 |
Correct |
29 ms |
25464 KB |
Output is correct |
34 |
Correct |
22 ms |
25480 KB |
Output is correct |
35 |
Correct |
170 ms |
42920 KB |
Output is correct |
36 |
Correct |
183 ms |
42836 KB |
Output is correct |
37 |
Correct |
170 ms |
42284 KB |
Output is correct |
38 |
Correct |
167 ms |
42648 KB |
Output is correct |
39 |
Correct |
161 ms |
42832 KB |
Output is correct |
40 |
Correct |
89 ms |
34428 KB |
Output is correct |
41 |
Correct |
87 ms |
34408 KB |
Output is correct |
42 |
Correct |
74 ms |
31940 KB |
Output is correct |
43 |
Correct |
74 ms |
30944 KB |
Output is correct |
44 |
Correct |
99 ms |
34900 KB |
Output is correct |
45 |
Correct |
86 ms |
34732 KB |
Output is correct |
46 |
Correct |
77 ms |
32272 KB |
Output is correct |
47 |
Correct |
74 ms |
31064 KB |
Output is correct |
48 |
Execution timed out |
2604 ms |
251856 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
4 ms |
23900 KB |
Output is correct |
3 |
Correct |
6 ms |
23928 KB |
Output is correct |
4 |
Correct |
4 ms |
23900 KB |
Output is correct |
5 |
Correct |
5 ms |
23708 KB |
Output is correct |
6 |
Correct |
5 ms |
23900 KB |
Output is correct |
7 |
Correct |
5 ms |
23900 KB |
Output is correct |
8 |
Correct |
5 ms |
23936 KB |
Output is correct |
9 |
Correct |
6 ms |
23900 KB |
Output is correct |
10 |
Correct |
6 ms |
23900 KB |
Output is correct |
11 |
Correct |
5 ms |
23904 KB |
Output is correct |
12 |
Correct |
4 ms |
23900 KB |
Output is correct |
13 |
Correct |
6 ms |
23928 KB |
Output is correct |
14 |
Correct |
5 ms |
23900 KB |
Output is correct |
15 |
Correct |
6 ms |
23900 KB |
Output is correct |
16 |
Correct |
5 ms |
23900 KB |
Output is correct |
17 |
Correct |
5 ms |
23928 KB |
Output is correct |
18 |
Correct |
6 ms |
23900 KB |
Output is correct |
19 |
Correct |
5 ms |
23900 KB |
Output is correct |
20 |
Correct |
7 ms |
23928 KB |
Output is correct |
21 |
Correct |
5 ms |
23936 KB |
Output is correct |
22 |
Correct |
7 ms |
23900 KB |
Output is correct |
23 |
Correct |
6 ms |
23900 KB |
Output is correct |
24 |
Correct |
5 ms |
23900 KB |
Output is correct |
25 |
Correct |
4 ms |
23932 KB |
Output is correct |
26 |
Correct |
5 ms |
23932 KB |
Output is correct |
27 |
Correct |
32 ms |
25688 KB |
Output is correct |
28 |
Correct |
20 ms |
25436 KB |
Output is correct |
29 |
Correct |
25 ms |
25432 KB |
Output is correct |
30 |
Correct |
22 ms |
25548 KB |
Output is correct |
31 |
Correct |
28 ms |
25756 KB |
Output is correct |
32 |
Correct |
22 ms |
25368 KB |
Output is correct |
33 |
Correct |
29 ms |
25464 KB |
Output is correct |
34 |
Correct |
22 ms |
25480 KB |
Output is correct |
35 |
Correct |
170 ms |
42920 KB |
Output is correct |
36 |
Correct |
183 ms |
42836 KB |
Output is correct |
37 |
Correct |
170 ms |
42284 KB |
Output is correct |
38 |
Correct |
167 ms |
42648 KB |
Output is correct |
39 |
Correct |
161 ms |
42832 KB |
Output is correct |
40 |
Correct |
89 ms |
34428 KB |
Output is correct |
41 |
Correct |
87 ms |
34408 KB |
Output is correct |
42 |
Correct |
74 ms |
31940 KB |
Output is correct |
43 |
Correct |
74 ms |
30944 KB |
Output is correct |
44 |
Correct |
99 ms |
34900 KB |
Output is correct |
45 |
Correct |
86 ms |
34732 KB |
Output is correct |
46 |
Correct |
77 ms |
32272 KB |
Output is correct |
47 |
Correct |
74 ms |
31064 KB |
Output is correct |
48 |
Execution timed out |
2604 ms |
251856 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |