Submission #670489

# Submission time Handle Problem Language Result Execution time Memory
670489 2022-12-09T09:11:52 Z Mahdi Rope (JOI17_rope) C++17
100 / 100
1035 ms 82936 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];
bool mk[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;
    }
    priority_queue<pii>pq;
    set<pii>s;
    for(int i=1;i<=m;++i)
        pq.push({cnt[i], i});
    for(int i=1;i<=m;++i){
        vector<int>w, ww;
        mk[i]=1;
        for(int u: v[i]){
            int z=u+((u&1) ? -1 : 1);
            if(z>0 && z<=n && c[z]!=i){
                z=c[z];
                --cnt[z];
                mk[z]=1;
                w.push_back(z);
            }
        }
        while(!pq.empty() && mk[pq.top().S]){
            ww.push_back(pq.top().S);
            pq.pop();
        }
        ans[i]=(pq.empty() ? 0 : pq.top().F);
        for(int u: w)
            ans[i]=max(ans[i], cnt[u]);
        for(int u: w){
            ++cnt[u];
            mk[u]=0;
        }
        mk[i]=0;
        for(int u: ww)
            pq.push({cnt[u], u});
    }
    for(int i=1;i<=m;++i){
        vector<int>w, ww;
        mk[i]=1;
        for(int u: v[i]){
            int z=u+((u&1) ? 1 : -1);
            if(z>0 && z<=n && c[z]!=i){
                z=c[z];
                --cnt[z];
                mk[z]=1;
                w.push_back(z);
            }
        }
        while(!pq.empty() && mk[pq.top().S]){
            ww.push_back(pq.top().S);
            pq.pop();
        }
        ans[i]=max(ans[i], (pq.empty() ? 0 : pq.top().F));
        for(int u: w)
            ans[i]=max(ans[i], cnt[u]);
        for(int u: w){
            ++cnt[u];
            mk[u]=0;
        }
        mk[i]=0;
        for(int u: ww)
            pq.push({cnt[u], u});
    }
    for(int i=1;i<=m;++i)
        cout<<n-cnt[i]-ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 11 ms 23736 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23752 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 12 ms 23748 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23824 KB Output is correct
15 Correct 11 ms 23784 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23704 KB Output is correct
21 Correct 12 ms 23812 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23708 KB Output is correct
24 Correct 11 ms 23728 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 11 ms 23736 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23752 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 12 ms 23748 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23824 KB Output is correct
15 Correct 11 ms 23784 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23704 KB Output is correct
21 Correct 12 ms 23812 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23708 KB Output is correct
24 Correct 11 ms 23728 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23712 KB Output is correct
27 Correct 20 ms 24772 KB Output is correct
28 Correct 19 ms 24892 KB Output is correct
29 Correct 20 ms 24788 KB Output is correct
30 Correct 18 ms 24788 KB Output is correct
31 Correct 22 ms 24788 KB Output is correct
32 Correct 21 ms 24928 KB Output is correct
33 Correct 19 ms 24916 KB Output is correct
34 Correct 22 ms 24884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 11 ms 23736 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23752 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 12 ms 23748 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23824 KB Output is correct
15 Correct 11 ms 23784 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23704 KB Output is correct
21 Correct 12 ms 23812 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23708 KB Output is correct
24 Correct 11 ms 23728 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23712 KB Output is correct
27 Correct 20 ms 24772 KB Output is correct
28 Correct 19 ms 24892 KB Output is correct
29 Correct 20 ms 24788 KB Output is correct
30 Correct 18 ms 24788 KB Output is correct
31 Correct 22 ms 24788 KB Output is correct
32 Correct 21 ms 24928 KB Output is correct
33 Correct 19 ms 24916 KB Output is correct
34 Correct 22 ms 24884 KB Output is correct
35 Correct 21 ms 24788 KB Output is correct
36 Correct 22 ms 24800 KB Output is correct
37 Correct 23 ms 24804 KB Output is correct
38 Correct 22 ms 24724 KB Output is correct
39 Correct 22 ms 24720 KB Output is correct
40 Correct 23 ms 24876 KB Output is correct
41 Correct 22 ms 24788 KB Output is correct
42 Correct 23 ms 24760 KB Output is correct
43 Correct 23 ms 24916 KB Output is correct
44 Correct 25 ms 24880 KB Output is correct
45 Correct 24 ms 24868 KB Output is correct
46 Correct 23 ms 24788 KB Output is correct
47 Correct 23 ms 24796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 11 ms 23736 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23752 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 12 ms 23748 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23824 KB Output is correct
15 Correct 11 ms 23784 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23704 KB Output is correct
21 Correct 12 ms 23812 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23708 KB Output is correct
24 Correct 11 ms 23728 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23712 KB Output is correct
27 Correct 20 ms 24772 KB Output is correct
28 Correct 19 ms 24892 KB Output is correct
29 Correct 20 ms 24788 KB Output is correct
30 Correct 18 ms 24788 KB Output is correct
31 Correct 22 ms 24788 KB Output is correct
32 Correct 21 ms 24928 KB Output is correct
33 Correct 19 ms 24916 KB Output is correct
34 Correct 22 ms 24884 KB Output is correct
35 Correct 21 ms 24788 KB Output is correct
36 Correct 22 ms 24800 KB Output is correct
37 Correct 23 ms 24804 KB Output is correct
38 Correct 22 ms 24724 KB Output is correct
39 Correct 22 ms 24720 KB Output is correct
40 Correct 23 ms 24876 KB Output is correct
41 Correct 22 ms 24788 KB Output is correct
42 Correct 23 ms 24760 KB Output is correct
43 Correct 23 ms 24916 KB Output is correct
44 Correct 25 ms 24880 KB Output is correct
45 Correct 24 ms 24868 KB Output is correct
46 Correct 23 ms 24788 KB Output is correct
47 Correct 23 ms 24796 KB Output is correct
48 Correct 148 ms 34420 KB Output is correct
49 Correct 146 ms 34436 KB Output is correct
50 Correct 148 ms 34504 KB Output is correct
51 Correct 141 ms 34440 KB Output is correct
52 Correct 130 ms 33356 KB Output is correct
53 Correct 142 ms 33620 KB Output is correct
54 Correct 165 ms 32600 KB Output is correct
55 Correct 151 ms 32384 KB Output is correct
56 Correct 148 ms 32116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 11 ms 23736 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23832 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 12 ms 23752 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 12 ms 23748 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 11 ms 23824 KB Output is correct
15 Correct 11 ms 23784 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 11 ms 23764 KB Output is correct
18 Correct 13 ms 23772 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 13 ms 23704 KB Output is correct
21 Correct 12 ms 23812 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23708 KB Output is correct
24 Correct 11 ms 23728 KB Output is correct
25 Correct 12 ms 23764 KB Output is correct
26 Correct 12 ms 23712 KB Output is correct
27 Correct 20 ms 24772 KB Output is correct
28 Correct 19 ms 24892 KB Output is correct
29 Correct 20 ms 24788 KB Output is correct
30 Correct 18 ms 24788 KB Output is correct
31 Correct 22 ms 24788 KB Output is correct
32 Correct 21 ms 24928 KB Output is correct
33 Correct 19 ms 24916 KB Output is correct
34 Correct 22 ms 24884 KB Output is correct
35 Correct 21 ms 24788 KB Output is correct
36 Correct 22 ms 24800 KB Output is correct
37 Correct 23 ms 24804 KB Output is correct
38 Correct 22 ms 24724 KB Output is correct
39 Correct 22 ms 24720 KB Output is correct
40 Correct 23 ms 24876 KB Output is correct
41 Correct 22 ms 24788 KB Output is correct
42 Correct 23 ms 24760 KB Output is correct
43 Correct 23 ms 24916 KB Output is correct
44 Correct 25 ms 24880 KB Output is correct
45 Correct 24 ms 24868 KB Output is correct
46 Correct 23 ms 24788 KB Output is correct
47 Correct 23 ms 24796 KB Output is correct
48 Correct 148 ms 34420 KB Output is correct
49 Correct 146 ms 34436 KB Output is correct
50 Correct 148 ms 34504 KB Output is correct
51 Correct 141 ms 34440 KB Output is correct
52 Correct 130 ms 33356 KB Output is correct
53 Correct 142 ms 33620 KB Output is correct
54 Correct 165 ms 32600 KB Output is correct
55 Correct 151 ms 32384 KB Output is correct
56 Correct 148 ms 32116 KB Output is correct
57 Correct 1035 ms 82936 KB Output is correct
58 Correct 808 ms 67496 KB Output is correct
59 Correct 788 ms 67428 KB Output is correct
60 Correct 973 ms 72936 KB Output is correct
61 Correct 910 ms 72992 KB Output is correct
62 Correct 391 ms 54076 KB Output is correct
63 Correct 543 ms 60092 KB Output is correct
64 Correct 440 ms 56204 KB Output is correct
65 Correct 262 ms 46252 KB Output is correct