Submission #991323

# Submission time Handle Problem Language Result Execution time Memory
991323 2024-06-02T03:17:15 Z irmuun Rope (JOI17_rope) C++17
100 / 100
1713 ms 147196 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll c[n+5];
    vector<ll>pos[m+5],cnt(m+5,0);
    for(ll i=1;i<=n;i++){
        cin>>c[i];
        cnt[c[i]]++;
        pos[c[i]].pb(i);
    }
    vector<ll>even(m+5,0),odd(m+5,0);
    multiset<ll,greater<ll>>C;
    for(ll i=1;i<=m;i++){
        C.insert(cnt[i]);
    }
    for(ll i=1;i<=m;i++){
        set<ll>st;
        for(ll p:pos[i]){
            if(p>1&&c[p-1]!=i){
                if(p%2==0) even[c[p-1]]++;
                else odd[c[p-1]]++;
                st.insert(c[p-1]);
            }
            if(p<n&&c[p+1]!=i){
                if(p%2==1) even[c[p+1]]++;
                else odd[c[p+1]]++;
                st.insert(c[p+1]);
            }
        }
        ll ans=n;
        C.erase(C.find(cnt[i]));
        for(ll x:st){
            ans=min(ans,n-cnt[i]-cnt[x]+min(odd[x],even[x]));
            C.erase(C.find(cnt[x]));
        }
        if(!C.empty()){
            ans=min(ans,n-cnt[i]-*C.begin());
        }
        ans=min(ans,n-cnt[i]);
        cout<<ans<<'\n';
        for(ll x:st){
            odd[x]=0;
            even[x]=0;
            C.insert(cnt[x]);
        }
        C.insert(cnt[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 2652 KB Output is correct
28 Correct 7 ms 2264 KB Output is correct
29 Correct 8 ms 2624 KB Output is correct
30 Correct 7 ms 2280 KB Output is correct
31 Correct 10 ms 2596 KB Output is correct
32 Correct 6 ms 2344 KB Output is correct
33 Correct 8 ms 2396 KB Output is correct
34 Correct 7 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 2652 KB Output is correct
28 Correct 7 ms 2264 KB Output is correct
29 Correct 8 ms 2624 KB Output is correct
30 Correct 7 ms 2280 KB Output is correct
31 Correct 10 ms 2596 KB Output is correct
32 Correct 6 ms 2344 KB Output is correct
33 Correct 8 ms 2396 KB Output is correct
34 Correct 7 ms 2396 KB Output is correct
35 Correct 43 ms 2652 KB Output is correct
36 Correct 47 ms 2652 KB Output is correct
37 Correct 40 ms 2652 KB Output is correct
38 Correct 39 ms 2652 KB Output is correct
39 Correct 40 ms 2652 KB Output is correct
40 Correct 23 ms 2908 KB Output is correct
41 Correct 23 ms 2940 KB Output is correct
42 Correct 18 ms 2652 KB Output is correct
43 Correct 17 ms 2908 KB Output is correct
44 Correct 24 ms 2728 KB Output is correct
45 Correct 24 ms 2908 KB Output is correct
46 Correct 19 ms 2652 KB Output is correct
47 Correct 18 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 2652 KB Output is correct
28 Correct 7 ms 2264 KB Output is correct
29 Correct 8 ms 2624 KB Output is correct
30 Correct 7 ms 2280 KB Output is correct
31 Correct 10 ms 2596 KB Output is correct
32 Correct 6 ms 2344 KB Output is correct
33 Correct 8 ms 2396 KB Output is correct
34 Correct 7 ms 2396 KB Output is correct
35 Correct 43 ms 2652 KB Output is correct
36 Correct 47 ms 2652 KB Output is correct
37 Correct 40 ms 2652 KB Output is correct
38 Correct 39 ms 2652 KB Output is correct
39 Correct 40 ms 2652 KB Output is correct
40 Correct 23 ms 2908 KB Output is correct
41 Correct 23 ms 2940 KB Output is correct
42 Correct 18 ms 2652 KB Output is correct
43 Correct 17 ms 2908 KB Output is correct
44 Correct 24 ms 2728 KB Output is correct
45 Correct 24 ms 2908 KB Output is correct
46 Correct 19 ms 2652 KB Output is correct
47 Correct 18 ms 2908 KB Output is correct
48 Correct 683 ms 26200 KB Output is correct
49 Correct 725 ms 26196 KB Output is correct
50 Correct 678 ms 26196 KB Output is correct
51 Correct 473 ms 25448 KB Output is correct
52 Correct 350 ms 23124 KB Output is correct
53 Correct 340 ms 24576 KB Output is correct
54 Correct 252 ms 22356 KB Output is correct
55 Correct 232 ms 22108 KB Output is correct
56 Correct 180 ms 21476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 2652 KB Output is correct
28 Correct 7 ms 2264 KB Output is correct
29 Correct 8 ms 2624 KB Output is correct
30 Correct 7 ms 2280 KB Output is correct
31 Correct 10 ms 2596 KB Output is correct
32 Correct 6 ms 2344 KB Output is correct
33 Correct 8 ms 2396 KB Output is correct
34 Correct 7 ms 2396 KB Output is correct
35 Correct 43 ms 2652 KB Output is correct
36 Correct 47 ms 2652 KB Output is correct
37 Correct 40 ms 2652 KB Output is correct
38 Correct 39 ms 2652 KB Output is correct
39 Correct 40 ms 2652 KB Output is correct
40 Correct 23 ms 2908 KB Output is correct
41 Correct 23 ms 2940 KB Output is correct
42 Correct 18 ms 2652 KB Output is correct
43 Correct 17 ms 2908 KB Output is correct
44 Correct 24 ms 2728 KB Output is correct
45 Correct 24 ms 2908 KB Output is correct
46 Correct 19 ms 2652 KB Output is correct
47 Correct 18 ms 2908 KB Output is correct
48 Correct 683 ms 26200 KB Output is correct
49 Correct 725 ms 26196 KB Output is correct
50 Correct 678 ms 26196 KB Output is correct
51 Correct 473 ms 25448 KB Output is correct
52 Correct 350 ms 23124 KB Output is correct
53 Correct 340 ms 24576 KB Output is correct
54 Correct 252 ms 22356 KB Output is correct
55 Correct 232 ms 22108 KB Output is correct
56 Correct 180 ms 21476 KB Output is correct
57 Correct 1563 ms 147196 KB Output is correct
58 Correct 1626 ms 95644 KB Output is correct
59 Correct 1657 ms 95456 KB Output is correct
60 Correct 1713 ms 108208 KB Output is correct
61 Correct 1689 ms 108116 KB Output is correct
62 Correct 621 ms 60500 KB Output is correct
63 Correct 1059 ms 75860 KB Output is correct
64 Correct 845 ms 66552 KB Output is correct
65 Correct 364 ms 42268 KB Output is correct