# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1001015 |
2024-06-18T12:50:02 Z |
Otalp |
Rope (JOI17_rope) |
C++14 |
|
2320 ms |
262144 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<ll, int> dp[2];
int cnt[1001000];
int a[1001000];
vector<int> d[1000100];
ll h(ll a, ll b){
return a * 1e7 + b;
}
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());
for(int i=1; i+1<=n; i+=2){
int l=a[i], r=a[i + 1];
dp[1][h(l, r)] ++;
dp[1][h(r, l)] ++;
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][h(l, r)] ++;
dp[0][h(r, l)] ++;
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][h(i, j)]);
}
us[j] = 1;
}
while(ls >= 0 and 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 |
9 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23900 KB |
Output is correct |
3 |
Correct |
12 ms |
23884 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23876 KB |
Output is correct |
8 |
Correct |
9 ms |
23896 KB |
Output is correct |
9 |
Correct |
9 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
12 |
Correct |
9 ms |
23944 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
9 ms |
23744 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
9 ms |
23720 KB |
Output is correct |
17 |
Correct |
9 ms |
23896 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
9 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
10 ms |
23904 KB |
Output is correct |
23 |
Correct |
9 ms |
23896 KB |
Output is correct |
24 |
Correct |
9 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23756 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23900 KB |
Output is correct |
3 |
Correct |
12 ms |
23884 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23876 KB |
Output is correct |
8 |
Correct |
9 ms |
23896 KB |
Output is correct |
9 |
Correct |
9 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
12 |
Correct |
9 ms |
23944 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
9 ms |
23744 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
9 ms |
23720 KB |
Output is correct |
17 |
Correct |
9 ms |
23896 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
9 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
10 ms |
23904 KB |
Output is correct |
23 |
Correct |
9 ms |
23896 KB |
Output is correct |
24 |
Correct |
9 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23756 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
29 ms |
25568 KB |
Output is correct |
28 |
Correct |
24 ms |
25428 KB |
Output is correct |
29 |
Correct |
33 ms |
25348 KB |
Output is correct |
30 |
Correct |
24 ms |
25292 KB |
Output is correct |
31 |
Correct |
30 ms |
25432 KB |
Output is correct |
32 |
Correct |
25 ms |
25176 KB |
Output is correct |
33 |
Correct |
35 ms |
25192 KB |
Output is correct |
34 |
Correct |
24 ms |
25476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23900 KB |
Output is correct |
3 |
Correct |
12 ms |
23884 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23876 KB |
Output is correct |
8 |
Correct |
9 ms |
23896 KB |
Output is correct |
9 |
Correct |
9 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
12 |
Correct |
9 ms |
23944 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
9 ms |
23744 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
9 ms |
23720 KB |
Output is correct |
17 |
Correct |
9 ms |
23896 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
9 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
10 ms |
23904 KB |
Output is correct |
23 |
Correct |
9 ms |
23896 KB |
Output is correct |
24 |
Correct |
9 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23756 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
29 ms |
25568 KB |
Output is correct |
28 |
Correct |
24 ms |
25428 KB |
Output is correct |
29 |
Correct |
33 ms |
25348 KB |
Output is correct |
30 |
Correct |
24 ms |
25292 KB |
Output is correct |
31 |
Correct |
30 ms |
25432 KB |
Output is correct |
32 |
Correct |
25 ms |
25176 KB |
Output is correct |
33 |
Correct |
35 ms |
25192 KB |
Output is correct |
34 |
Correct |
24 ms |
25476 KB |
Output is correct |
35 |
Correct |
158 ms |
42500 KB |
Output is correct |
36 |
Correct |
135 ms |
42320 KB |
Output is correct |
37 |
Correct |
140 ms |
42064 KB |
Output is correct |
38 |
Correct |
149 ms |
42324 KB |
Output is correct |
39 |
Correct |
137 ms |
42324 KB |
Output is correct |
40 |
Correct |
82 ms |
34128 KB |
Output is correct |
41 |
Correct |
90 ms |
34132 KB |
Output is correct |
42 |
Correct |
72 ms |
31484 KB |
Output is correct |
43 |
Correct |
72 ms |
30684 KB |
Output is correct |
44 |
Correct |
89 ms |
34384 KB |
Output is correct |
45 |
Correct |
90 ms |
34388 KB |
Output is correct |
46 |
Correct |
71 ms |
31764 KB |
Output is correct |
47 |
Correct |
68 ms |
30804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23900 KB |
Output is correct |
3 |
Correct |
12 ms |
23884 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23876 KB |
Output is correct |
8 |
Correct |
9 ms |
23896 KB |
Output is correct |
9 |
Correct |
9 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
12 |
Correct |
9 ms |
23944 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
9 ms |
23744 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
9 ms |
23720 KB |
Output is correct |
17 |
Correct |
9 ms |
23896 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
9 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
10 ms |
23904 KB |
Output is correct |
23 |
Correct |
9 ms |
23896 KB |
Output is correct |
24 |
Correct |
9 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23756 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
29 ms |
25568 KB |
Output is correct |
28 |
Correct |
24 ms |
25428 KB |
Output is correct |
29 |
Correct |
33 ms |
25348 KB |
Output is correct |
30 |
Correct |
24 ms |
25292 KB |
Output is correct |
31 |
Correct |
30 ms |
25432 KB |
Output is correct |
32 |
Correct |
25 ms |
25176 KB |
Output is correct |
33 |
Correct |
35 ms |
25192 KB |
Output is correct |
34 |
Correct |
24 ms |
25476 KB |
Output is correct |
35 |
Correct |
158 ms |
42500 KB |
Output is correct |
36 |
Correct |
135 ms |
42320 KB |
Output is correct |
37 |
Correct |
140 ms |
42064 KB |
Output is correct |
38 |
Correct |
149 ms |
42324 KB |
Output is correct |
39 |
Correct |
137 ms |
42324 KB |
Output is correct |
40 |
Correct |
82 ms |
34128 KB |
Output is correct |
41 |
Correct |
90 ms |
34132 KB |
Output is correct |
42 |
Correct |
72 ms |
31484 KB |
Output is correct |
43 |
Correct |
72 ms |
30684 KB |
Output is correct |
44 |
Correct |
89 ms |
34384 KB |
Output is correct |
45 |
Correct |
90 ms |
34388 KB |
Output is correct |
46 |
Correct |
71 ms |
31764 KB |
Output is correct |
47 |
Correct |
68 ms |
30804 KB |
Output is correct |
48 |
Runtime error |
2320 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23896 KB |
Output is correct |
2 |
Correct |
9 ms |
23900 KB |
Output is correct |
3 |
Correct |
12 ms |
23884 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23876 KB |
Output is correct |
8 |
Correct |
9 ms |
23896 KB |
Output is correct |
9 |
Correct |
9 ms |
23900 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
9 ms |
23896 KB |
Output is correct |
12 |
Correct |
9 ms |
23944 KB |
Output is correct |
13 |
Correct |
9 ms |
23900 KB |
Output is correct |
14 |
Correct |
9 ms |
23744 KB |
Output is correct |
15 |
Correct |
11 ms |
23900 KB |
Output is correct |
16 |
Correct |
9 ms |
23720 KB |
Output is correct |
17 |
Correct |
9 ms |
23896 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
9 ms |
23820 KB |
Output is correct |
20 |
Correct |
12 ms |
23900 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
10 ms |
23904 KB |
Output is correct |
23 |
Correct |
9 ms |
23896 KB |
Output is correct |
24 |
Correct |
9 ms |
23900 KB |
Output is correct |
25 |
Correct |
10 ms |
23756 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
29 ms |
25568 KB |
Output is correct |
28 |
Correct |
24 ms |
25428 KB |
Output is correct |
29 |
Correct |
33 ms |
25348 KB |
Output is correct |
30 |
Correct |
24 ms |
25292 KB |
Output is correct |
31 |
Correct |
30 ms |
25432 KB |
Output is correct |
32 |
Correct |
25 ms |
25176 KB |
Output is correct |
33 |
Correct |
35 ms |
25192 KB |
Output is correct |
34 |
Correct |
24 ms |
25476 KB |
Output is correct |
35 |
Correct |
158 ms |
42500 KB |
Output is correct |
36 |
Correct |
135 ms |
42320 KB |
Output is correct |
37 |
Correct |
140 ms |
42064 KB |
Output is correct |
38 |
Correct |
149 ms |
42324 KB |
Output is correct |
39 |
Correct |
137 ms |
42324 KB |
Output is correct |
40 |
Correct |
82 ms |
34128 KB |
Output is correct |
41 |
Correct |
90 ms |
34132 KB |
Output is correct |
42 |
Correct |
72 ms |
31484 KB |
Output is correct |
43 |
Correct |
72 ms |
30684 KB |
Output is correct |
44 |
Correct |
89 ms |
34384 KB |
Output is correct |
45 |
Correct |
90 ms |
34388 KB |
Output is correct |
46 |
Correct |
71 ms |
31764 KB |
Output is correct |
47 |
Correct |
68 ms |
30804 KB |
Output is correct |
48 |
Runtime error |
2320 ms |
262144 KB |
Execution killed with signal 9 |
49 |
Halted |
0 ms |
0 KB |
- |