답안 #1001095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001095 2024-06-18T14:28:41 Z Otalp Rope (JOI17_rope) C++17
80 / 100
2500 ms 244680 KB
#include<bits/stdc++.h>
using namespace std;
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#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];
int 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] = i;
    }
    sort(g + 1, g + 1 + m, cmp);
 
    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] == 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]-cnt[g[ls]]);
        cout<<ans<<'\n';
    }
}


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






















Compilation message

rope.cpp:3: warning: ignoring '#pragma optimization_level ' [-Wunknown-pragmas]
    3 | #pragma optimization_level 3
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29016 KB Output is correct
2 Correct 4 ms 29152 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 27104 KB Output is correct
6 Correct 5 ms 29112 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29140 KB Output is correct
9 Correct 5 ms 25436 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 29068 KB Output is correct
13 Correct 5 ms 25436 KB Output is correct
14 Correct 6 ms 27484 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 8 ms 29128 KB Output is correct
17 Correct 5 ms 29112 KB Output is correct
18 Correct 4 ms 29020 KB Output is correct
19 Correct 5 ms 29136 KB Output is correct
20 Correct 5 ms 29108 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 29164 KB Output is correct
23 Correct 7 ms 26972 KB Output is correct
24 Correct 5 ms 25436 KB Output is correct
25 Correct 8 ms 29104 KB Output is correct
26 Correct 5 ms 25436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29016 KB Output is correct
2 Correct 4 ms 29152 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 27104 KB Output is correct
6 Correct 5 ms 29112 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29140 KB Output is correct
9 Correct 5 ms 25436 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 29068 KB Output is correct
13 Correct 5 ms 25436 KB Output is correct
14 Correct 6 ms 27484 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 8 ms 29128 KB Output is correct
17 Correct 5 ms 29112 KB Output is correct
18 Correct 4 ms 29020 KB Output is correct
19 Correct 5 ms 29136 KB Output is correct
20 Correct 5 ms 29108 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 29164 KB Output is correct
23 Correct 7 ms 26972 KB Output is correct
24 Correct 5 ms 25436 KB Output is correct
25 Correct 8 ms 29104 KB Output is correct
26 Correct 5 ms 25436 KB Output is correct
27 Correct 28 ms 27228 KB Output is correct
28 Correct 22 ms 30292 KB Output is correct
29 Correct 25 ms 30296 KB Output is correct
30 Correct 22 ms 27084 KB Output is correct
31 Correct 24 ms 27076 KB Output is correct
32 Correct 21 ms 26904 KB Output is correct
33 Correct 28 ms 29176 KB Output is correct
34 Correct 21 ms 30220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29016 KB Output is correct
2 Correct 4 ms 29152 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 27104 KB Output is correct
6 Correct 5 ms 29112 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29140 KB Output is correct
9 Correct 5 ms 25436 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 29068 KB Output is correct
13 Correct 5 ms 25436 KB Output is correct
14 Correct 6 ms 27484 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 8 ms 29128 KB Output is correct
17 Correct 5 ms 29112 KB Output is correct
18 Correct 4 ms 29020 KB Output is correct
19 Correct 5 ms 29136 KB Output is correct
20 Correct 5 ms 29108 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 29164 KB Output is correct
23 Correct 7 ms 26972 KB Output is correct
24 Correct 5 ms 25436 KB Output is correct
25 Correct 8 ms 29104 KB Output is correct
26 Correct 5 ms 25436 KB Output is correct
27 Correct 28 ms 27228 KB Output is correct
28 Correct 22 ms 30292 KB Output is correct
29 Correct 25 ms 30296 KB Output is correct
30 Correct 22 ms 27084 KB Output is correct
31 Correct 24 ms 27076 KB Output is correct
32 Correct 21 ms 26904 KB Output is correct
33 Correct 28 ms 29176 KB Output is correct
34 Correct 21 ms 30220 KB Output is correct
35 Correct 77 ms 38208 KB Output is correct
36 Correct 71 ms 41272 KB Output is correct
37 Correct 59 ms 37904 KB Output is correct
38 Correct 64 ms 39300 KB Output is correct
39 Correct 73 ms 38312 KB Output is correct
40 Correct 41 ms 32868 KB Output is correct
41 Correct 41 ms 32876 KB Output is correct
42 Correct 47 ms 32608 KB Output is correct
43 Correct 37 ms 33708 KB Output is correct
44 Correct 54 ms 32944 KB Output is correct
45 Correct 44 ms 34144 KB Output is correct
46 Correct 39 ms 34836 KB Output is correct
47 Correct 38 ms 30392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29016 KB Output is correct
2 Correct 4 ms 29152 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 27104 KB Output is correct
6 Correct 5 ms 29112 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29140 KB Output is correct
9 Correct 5 ms 25436 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 29068 KB Output is correct
13 Correct 5 ms 25436 KB Output is correct
14 Correct 6 ms 27484 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 8 ms 29128 KB Output is correct
17 Correct 5 ms 29112 KB Output is correct
18 Correct 4 ms 29020 KB Output is correct
19 Correct 5 ms 29136 KB Output is correct
20 Correct 5 ms 29108 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 29164 KB Output is correct
23 Correct 7 ms 26972 KB Output is correct
24 Correct 5 ms 25436 KB Output is correct
25 Correct 8 ms 29104 KB Output is correct
26 Correct 5 ms 25436 KB Output is correct
27 Correct 28 ms 27228 KB Output is correct
28 Correct 22 ms 30292 KB Output is correct
29 Correct 25 ms 30296 KB Output is correct
30 Correct 22 ms 27084 KB Output is correct
31 Correct 24 ms 27076 KB Output is correct
32 Correct 21 ms 26904 KB Output is correct
33 Correct 28 ms 29176 KB Output is correct
34 Correct 21 ms 30220 KB Output is correct
35 Correct 77 ms 38208 KB Output is correct
36 Correct 71 ms 41272 KB Output is correct
37 Correct 59 ms 37904 KB Output is correct
38 Correct 64 ms 39300 KB Output is correct
39 Correct 73 ms 38312 KB Output is correct
40 Correct 41 ms 32868 KB Output is correct
41 Correct 41 ms 32876 KB Output is correct
42 Correct 47 ms 32608 KB Output is correct
43 Correct 37 ms 33708 KB Output is correct
44 Correct 54 ms 32944 KB Output is correct
45 Correct 44 ms 34144 KB Output is correct
46 Correct 39 ms 34836 KB Output is correct
47 Correct 38 ms 30392 KB Output is correct
48 Correct 1768 ms 201856 KB Output is correct
49 Correct 1641 ms 201836 KB Output is correct
50 Correct 1799 ms 201760 KB Output is correct
51 Correct 1135 ms 149016 KB Output is correct
52 Correct 721 ms 117036 KB Output is correct
53 Correct 745 ms 117048 KB Output is correct
54 Correct 520 ms 84880 KB Output is correct
55 Correct 526 ms 82876 KB Output is correct
56 Correct 475 ms 75768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 29016 KB Output is correct
2 Correct 4 ms 29152 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 27104 KB Output is correct
6 Correct 5 ms 29112 KB Output is correct
7 Correct 5 ms 29020 KB Output is correct
8 Correct 5 ms 29140 KB Output is correct
9 Correct 5 ms 25436 KB Output is correct
10 Correct 5 ms 29020 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 29068 KB Output is correct
13 Correct 5 ms 25436 KB Output is correct
14 Correct 6 ms 27484 KB Output is correct
15 Correct 5 ms 25436 KB Output is correct
16 Correct 8 ms 29128 KB Output is correct
17 Correct 5 ms 29112 KB Output is correct
18 Correct 4 ms 29020 KB Output is correct
19 Correct 5 ms 29136 KB Output is correct
20 Correct 5 ms 29108 KB Output is correct
21 Correct 5 ms 26972 KB Output is correct
22 Correct 5 ms 29164 KB Output is correct
23 Correct 7 ms 26972 KB Output is correct
24 Correct 5 ms 25436 KB Output is correct
25 Correct 8 ms 29104 KB Output is correct
26 Correct 5 ms 25436 KB Output is correct
27 Correct 28 ms 27228 KB Output is correct
28 Correct 22 ms 30292 KB Output is correct
29 Correct 25 ms 30296 KB Output is correct
30 Correct 22 ms 27084 KB Output is correct
31 Correct 24 ms 27076 KB Output is correct
32 Correct 21 ms 26904 KB Output is correct
33 Correct 28 ms 29176 KB Output is correct
34 Correct 21 ms 30220 KB Output is correct
35 Correct 77 ms 38208 KB Output is correct
36 Correct 71 ms 41272 KB Output is correct
37 Correct 59 ms 37904 KB Output is correct
38 Correct 64 ms 39300 KB Output is correct
39 Correct 73 ms 38312 KB Output is correct
40 Correct 41 ms 32868 KB Output is correct
41 Correct 41 ms 32876 KB Output is correct
42 Correct 47 ms 32608 KB Output is correct
43 Correct 37 ms 33708 KB Output is correct
44 Correct 54 ms 32944 KB Output is correct
45 Correct 44 ms 34144 KB Output is correct
46 Correct 39 ms 34836 KB Output is correct
47 Correct 38 ms 30392 KB Output is correct
48 Correct 1768 ms 201856 KB Output is correct
49 Correct 1641 ms 201836 KB Output is correct
50 Correct 1799 ms 201760 KB Output is correct
51 Correct 1135 ms 149016 KB Output is correct
52 Correct 721 ms 117036 KB Output is correct
53 Correct 745 ms 117048 KB Output is correct
54 Correct 520 ms 84880 KB Output is correct
55 Correct 526 ms 82876 KB Output is correct
56 Correct 475 ms 75768 KB Output is correct
57 Execution timed out 2543 ms 244680 KB Time limit exceeded
58 Halted 0 ms 0 KB -