답안 #1001090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001090 2024-06-18T14:22:58 Z Otalp Rope (JOI17_rope) C++17
80 / 100
2500 ms 249172 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
#define h(a, b) (ll)a * 1e7 + b
 
unordered_map<ll, int> dp[2];
int cnt[1000001];
int a[1000001];
vector<int> d[1000001];
pii g[1000001];

bool cmp(int a, int b){
    if(cnt[a] == cnt[b]) return a > b;
    return cnt[a] > cnt[b];
}

//ll h(ll a, ll b){ //hynya
//    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]] ++;
    }
    for(int i=1; i<=m; i++){
        g[i] = {cnt[i], i};
    }
    sort(g + 1, g + 1 + m, greater<pii>());
 
    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);
    }
    ll dd = 0;
    for(int i=1; i<=m; i++) dd += d[i].size();
    if(dd > 2e6) return;
    if(dp[0].size() + dp[1].size() > 2e6) return;
    for(int i=1; i<=m; i++){
        d[i].pb(i);
        sort(d[i].begin(), d[i].end(), cmp);
    }
    for(int i=1; i<=m; i++){
        int ans = n - cnt[i];
        int ls = 1;
        for(int j: d[i]){
            while(ls <= m and g[ls].ss == j) ls++;
            if(j == i) continue;
            for(int k=0; k<2; k++){ 
                ans = min(ans, n-cnt[i]-cnt[j]+dp[k][h(i, j)]);
            }
        }
        if(ls <= m) ans = min(ans, n-cnt[i]-g[ls].ff);
        cout<<ans<<'\n';
    }
}


signed main(){
    ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
    solve();
}






















# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 6 ms 25436 KB Output is correct
5 Correct 6 ms 25436 KB Output is correct
6 Correct 6 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 7 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25260 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25432 KB Output is correct
14 Correct 6 ms 25436 KB Output is correct
15 Correct 5 ms 25688 KB Output is correct
16 Correct 6 ms 25436 KB Output is correct
17 Correct 6 ms 25452 KB Output is correct
18 Correct 7 ms 25436 KB Output is correct
19 Correct 6 ms 25284 KB Output is correct
20 Correct 6 ms 25436 KB Output is correct
21 Correct 7 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 7 ms 25436 KB Output is correct
24 Correct 7 ms 25432 KB Output is correct
25 Correct 7 ms 25436 KB Output is correct
26 Correct 7 ms 25288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 6 ms 25436 KB Output is correct
5 Correct 6 ms 25436 KB Output is correct
6 Correct 6 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 7 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25260 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25432 KB Output is correct
14 Correct 6 ms 25436 KB Output is correct
15 Correct 5 ms 25688 KB Output is correct
16 Correct 6 ms 25436 KB Output is correct
17 Correct 6 ms 25452 KB Output is correct
18 Correct 7 ms 25436 KB Output is correct
19 Correct 6 ms 25284 KB Output is correct
20 Correct 6 ms 25436 KB Output is correct
21 Correct 7 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 7 ms 25436 KB Output is correct
24 Correct 7 ms 25432 KB Output is correct
25 Correct 7 ms 25436 KB Output is correct
26 Correct 7 ms 25288 KB Output is correct
27 Correct 25 ms 27124 KB Output is correct
28 Correct 26 ms 26840 KB Output is correct
29 Correct 23 ms 26716 KB Output is correct
30 Correct 23 ms 26832 KB Output is correct
31 Correct 23 ms 27084 KB Output is correct
32 Correct 21 ms 26644 KB Output is correct
33 Correct 26 ms 26716 KB Output is correct
34 Correct 23 ms 26964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 6 ms 25436 KB Output is correct
5 Correct 6 ms 25436 KB Output is correct
6 Correct 6 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 7 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25260 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25432 KB Output is correct
14 Correct 6 ms 25436 KB Output is correct
15 Correct 5 ms 25688 KB Output is correct
16 Correct 6 ms 25436 KB Output is correct
17 Correct 6 ms 25452 KB Output is correct
18 Correct 7 ms 25436 KB Output is correct
19 Correct 6 ms 25284 KB Output is correct
20 Correct 6 ms 25436 KB Output is correct
21 Correct 7 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 7 ms 25436 KB Output is correct
24 Correct 7 ms 25432 KB Output is correct
25 Correct 7 ms 25436 KB Output is correct
26 Correct 7 ms 25288 KB Output is correct
27 Correct 25 ms 27124 KB Output is correct
28 Correct 26 ms 26840 KB Output is correct
29 Correct 23 ms 26716 KB Output is correct
30 Correct 23 ms 26832 KB Output is correct
31 Correct 23 ms 27084 KB Output is correct
32 Correct 21 ms 26644 KB Output is correct
33 Correct 26 ms 26716 KB Output is correct
34 Correct 23 ms 26964 KB Output is correct
35 Correct 61 ms 38084 KB Output is correct
36 Correct 61 ms 38188 KB Output is correct
37 Correct 60 ms 37852 KB Output is correct
38 Correct 65 ms 37928 KB Output is correct
39 Correct 62 ms 38184 KB Output is correct
40 Correct 43 ms 32612 KB Output is correct
41 Correct 41 ms 32612 KB Output is correct
42 Correct 38 ms 31340 KB Output is correct
43 Correct 35 ms 30392 KB Output is correct
44 Correct 44 ms 32868 KB Output is correct
45 Correct 45 ms 32756 KB Output is correct
46 Correct 39 ms 31512 KB Output is correct
47 Correct 36 ms 30384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 6 ms 25436 KB Output is correct
5 Correct 6 ms 25436 KB Output is correct
6 Correct 6 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 7 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25260 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25432 KB Output is correct
14 Correct 6 ms 25436 KB Output is correct
15 Correct 5 ms 25688 KB Output is correct
16 Correct 6 ms 25436 KB Output is correct
17 Correct 6 ms 25452 KB Output is correct
18 Correct 7 ms 25436 KB Output is correct
19 Correct 6 ms 25284 KB Output is correct
20 Correct 6 ms 25436 KB Output is correct
21 Correct 7 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 7 ms 25436 KB Output is correct
24 Correct 7 ms 25432 KB Output is correct
25 Correct 7 ms 25436 KB Output is correct
26 Correct 7 ms 25288 KB Output is correct
27 Correct 25 ms 27124 KB Output is correct
28 Correct 26 ms 26840 KB Output is correct
29 Correct 23 ms 26716 KB Output is correct
30 Correct 23 ms 26832 KB Output is correct
31 Correct 23 ms 27084 KB Output is correct
32 Correct 21 ms 26644 KB Output is correct
33 Correct 26 ms 26716 KB Output is correct
34 Correct 23 ms 26964 KB Output is correct
35 Correct 61 ms 38084 KB Output is correct
36 Correct 61 ms 38188 KB Output is correct
37 Correct 60 ms 37852 KB Output is correct
38 Correct 65 ms 37928 KB Output is correct
39 Correct 62 ms 38184 KB Output is correct
40 Correct 43 ms 32612 KB Output is correct
41 Correct 41 ms 32612 KB Output is correct
42 Correct 38 ms 31340 KB Output is correct
43 Correct 35 ms 30392 KB Output is correct
44 Correct 44 ms 32868 KB Output is correct
45 Correct 45 ms 32756 KB Output is correct
46 Correct 39 ms 31512 KB Output is correct
47 Correct 36 ms 30384 KB Output is correct
48 Correct 1637 ms 199912 KB Output is correct
49 Correct 1724 ms 199744 KB Output is correct
50 Correct 1706 ms 199792 KB Output is correct
51 Correct 1038 ms 147040 KB Output is correct
52 Correct 793 ms 115172 KB Output is correct
53 Correct 769 ms 115240 KB Output is correct
54 Correct 523 ms 82908 KB Output is correct
55 Correct 544 ms 81292 KB Output is correct
56 Correct 452 ms 73804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25432 KB Output is correct
2 Correct 8 ms 25436 KB Output is correct
3 Correct 7 ms 25436 KB Output is correct
4 Correct 6 ms 25436 KB Output is correct
5 Correct 6 ms 25436 KB Output is correct
6 Correct 6 ms 25436 KB Output is correct
7 Correct 8 ms 25436 KB Output is correct
8 Correct 7 ms 25436 KB Output is correct
9 Correct 7 ms 25436 KB Output is correct
10 Correct 7 ms 25260 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25432 KB Output is correct
14 Correct 6 ms 25436 KB Output is correct
15 Correct 5 ms 25688 KB Output is correct
16 Correct 6 ms 25436 KB Output is correct
17 Correct 6 ms 25452 KB Output is correct
18 Correct 7 ms 25436 KB Output is correct
19 Correct 6 ms 25284 KB Output is correct
20 Correct 6 ms 25436 KB Output is correct
21 Correct 7 ms 25436 KB Output is correct
22 Correct 8 ms 25436 KB Output is correct
23 Correct 7 ms 25436 KB Output is correct
24 Correct 7 ms 25432 KB Output is correct
25 Correct 7 ms 25436 KB Output is correct
26 Correct 7 ms 25288 KB Output is correct
27 Correct 25 ms 27124 KB Output is correct
28 Correct 26 ms 26840 KB Output is correct
29 Correct 23 ms 26716 KB Output is correct
30 Correct 23 ms 26832 KB Output is correct
31 Correct 23 ms 27084 KB Output is correct
32 Correct 21 ms 26644 KB Output is correct
33 Correct 26 ms 26716 KB Output is correct
34 Correct 23 ms 26964 KB Output is correct
35 Correct 61 ms 38084 KB Output is correct
36 Correct 61 ms 38188 KB Output is correct
37 Correct 60 ms 37852 KB Output is correct
38 Correct 65 ms 37928 KB Output is correct
39 Correct 62 ms 38184 KB Output is correct
40 Correct 43 ms 32612 KB Output is correct
41 Correct 41 ms 32612 KB Output is correct
42 Correct 38 ms 31340 KB Output is correct
43 Correct 35 ms 30392 KB Output is correct
44 Correct 44 ms 32868 KB Output is correct
45 Correct 45 ms 32756 KB Output is correct
46 Correct 39 ms 31512 KB Output is correct
47 Correct 36 ms 30384 KB Output is correct
48 Correct 1637 ms 199912 KB Output is correct
49 Correct 1724 ms 199744 KB Output is correct
50 Correct 1706 ms 199792 KB Output is correct
51 Correct 1038 ms 147040 KB Output is correct
52 Correct 793 ms 115172 KB Output is correct
53 Correct 769 ms 115240 KB Output is correct
54 Correct 523 ms 82908 KB Output is correct
55 Correct 544 ms 81292 KB Output is correct
56 Correct 452 ms 73804 KB Output is correct
57 Execution timed out 2554 ms 249172 KB Time limit exceeded
58 Halted 0 ms 0 KB -