답안 #1001056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001056 2024-06-18T13:53:32 Z Otalp Rope (JOI17_rope) C++17
55 / 100
2004 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<pii, int> dp[2];
int cnt[1001000];
int a[1001000];
vector<int> d[1001000];
 

bool cmp(int a, int b){
    if(cnt[a] == cnt[b]) return a > b;
    return cnt[a] > cnt[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(), greater<pii>());
 
    for(int i=1; i+1<=n; i+=2){
        int l=a[i], r=a[i + 1];
        dp[1][{l, r}] ++;
        dp[1][{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][{l, r}] ++;
        dp[0][{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(g.size() == 0 or g.size() > 1e6) 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 = 0;
        for(int j: d[i]){
            while(ls < g.size() 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][{i, j}]);
            }
        }
        if(ls < g.size()) 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();
}






















Compilation message

rope.cpp: In function 'void solve()':
rope.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             while(ls < g.size() and g[ls].ss == j) ls++;
      |                   ~~~^~~~~~~~~~
rope.cpp:66:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if(ls < g.size()) ans = min(ans, n-cnt[i]-g[ls].ff);
      |            ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 27228 KB Output is correct
2 Correct 4 ms 27268 KB Output is correct
3 Correct 4 ms 27280 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27228 KB Output is correct
6 Correct 4 ms 27236 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 4 ms 27228 KB Output is correct
9 Correct 4 ms 27228 KB Output is correct
10 Correct 4 ms 27228 KB Output is correct
11 Correct 4 ms 27228 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 5 ms 27228 KB Output is correct
14 Correct 4 ms 27264 KB Output is correct
15 Correct 4 ms 27224 KB Output is correct
16 Correct 5 ms 27228 KB Output is correct
17 Correct 5 ms 27304 KB Output is correct
18 Correct 5 ms 27224 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 5 ms 27224 KB Output is correct
22 Correct 4 ms 27252 KB Output is correct
23 Correct 4 ms 27228 KB Output is correct
24 Correct 4 ms 27260 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 4 ms 27224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 27228 KB Output is correct
2 Correct 4 ms 27268 KB Output is correct
3 Correct 4 ms 27280 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27228 KB Output is correct
6 Correct 4 ms 27236 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 4 ms 27228 KB Output is correct
9 Correct 4 ms 27228 KB Output is correct
10 Correct 4 ms 27228 KB Output is correct
11 Correct 4 ms 27228 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 5 ms 27228 KB Output is correct
14 Correct 4 ms 27264 KB Output is correct
15 Correct 4 ms 27224 KB Output is correct
16 Correct 5 ms 27228 KB Output is correct
17 Correct 5 ms 27304 KB Output is correct
18 Correct 5 ms 27224 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 5 ms 27224 KB Output is correct
22 Correct 4 ms 27252 KB Output is correct
23 Correct 4 ms 27228 KB Output is correct
24 Correct 4 ms 27260 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 4 ms 27224 KB Output is correct
27 Correct 27 ms 28508 KB Output is correct
28 Correct 22 ms 28244 KB Output is correct
29 Correct 35 ms 28416 KB Output is correct
30 Correct 29 ms 28320 KB Output is correct
31 Correct 27 ms 28508 KB Output is correct
32 Correct 23 ms 28184 KB Output is correct
33 Correct 25 ms 28252 KB Output is correct
34 Correct 23 ms 28376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 27228 KB Output is correct
2 Correct 4 ms 27268 KB Output is correct
3 Correct 4 ms 27280 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27228 KB Output is correct
6 Correct 4 ms 27236 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 4 ms 27228 KB Output is correct
9 Correct 4 ms 27228 KB Output is correct
10 Correct 4 ms 27228 KB Output is correct
11 Correct 4 ms 27228 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 5 ms 27228 KB Output is correct
14 Correct 4 ms 27264 KB Output is correct
15 Correct 4 ms 27224 KB Output is correct
16 Correct 5 ms 27228 KB Output is correct
17 Correct 5 ms 27304 KB Output is correct
18 Correct 5 ms 27224 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 5 ms 27224 KB Output is correct
22 Correct 4 ms 27252 KB Output is correct
23 Correct 4 ms 27228 KB Output is correct
24 Correct 4 ms 27260 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 4 ms 27224 KB Output is correct
27 Correct 27 ms 28508 KB Output is correct
28 Correct 22 ms 28244 KB Output is correct
29 Correct 35 ms 28416 KB Output is correct
30 Correct 29 ms 28320 KB Output is correct
31 Correct 27 ms 28508 KB Output is correct
32 Correct 23 ms 28184 KB Output is correct
33 Correct 25 ms 28252 KB Output is correct
34 Correct 23 ms 28376 KB Output is correct
35 Correct 135 ms 45392 KB Output is correct
36 Correct 137 ms 45392 KB Output is correct
37 Correct 122 ms 44856 KB Output is correct
38 Correct 126 ms 45140 KB Output is correct
39 Correct 139 ms 45392 KB Output is correct
40 Correct 90 ms 37204 KB Output is correct
41 Correct 72 ms 36884 KB Output is correct
42 Correct 64 ms 34548 KB Output is correct
43 Correct 61 ms 33616 KB Output is correct
44 Correct 83 ms 37520 KB Output is correct
45 Correct 75 ms 37220 KB Output is correct
46 Correct 62 ms 34680 KB Output is correct
47 Correct 62 ms 33724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 27228 KB Output is correct
2 Correct 4 ms 27268 KB Output is correct
3 Correct 4 ms 27280 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27228 KB Output is correct
6 Correct 4 ms 27236 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 4 ms 27228 KB Output is correct
9 Correct 4 ms 27228 KB Output is correct
10 Correct 4 ms 27228 KB Output is correct
11 Correct 4 ms 27228 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 5 ms 27228 KB Output is correct
14 Correct 4 ms 27264 KB Output is correct
15 Correct 4 ms 27224 KB Output is correct
16 Correct 5 ms 27228 KB Output is correct
17 Correct 5 ms 27304 KB Output is correct
18 Correct 5 ms 27224 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 5 ms 27224 KB Output is correct
22 Correct 4 ms 27252 KB Output is correct
23 Correct 4 ms 27228 KB Output is correct
24 Correct 4 ms 27260 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 4 ms 27224 KB Output is correct
27 Correct 27 ms 28508 KB Output is correct
28 Correct 22 ms 28244 KB Output is correct
29 Correct 35 ms 28416 KB Output is correct
30 Correct 29 ms 28320 KB Output is correct
31 Correct 27 ms 28508 KB Output is correct
32 Correct 23 ms 28184 KB Output is correct
33 Correct 25 ms 28252 KB Output is correct
34 Correct 23 ms 28376 KB Output is correct
35 Correct 135 ms 45392 KB Output is correct
36 Correct 137 ms 45392 KB Output is correct
37 Correct 122 ms 44856 KB Output is correct
38 Correct 126 ms 45140 KB Output is correct
39 Correct 139 ms 45392 KB Output is correct
40 Correct 90 ms 37204 KB Output is correct
41 Correct 72 ms 36884 KB Output is correct
42 Correct 64 ms 34548 KB Output is correct
43 Correct 61 ms 33616 KB Output is correct
44 Correct 83 ms 37520 KB Output is correct
45 Correct 75 ms 37220 KB Output is correct
46 Correct 62 ms 34680 KB Output is correct
47 Correct 62 ms 33724 KB Output is correct
48 Runtime error 2004 ms 262144 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 27228 KB Output is correct
2 Correct 4 ms 27268 KB Output is correct
3 Correct 4 ms 27280 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27228 KB Output is correct
6 Correct 4 ms 27236 KB Output is correct
7 Correct 4 ms 27228 KB Output is correct
8 Correct 4 ms 27228 KB Output is correct
9 Correct 4 ms 27228 KB Output is correct
10 Correct 4 ms 27228 KB Output is correct
11 Correct 4 ms 27228 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 5 ms 27228 KB Output is correct
14 Correct 4 ms 27264 KB Output is correct
15 Correct 4 ms 27224 KB Output is correct
16 Correct 5 ms 27228 KB Output is correct
17 Correct 5 ms 27304 KB Output is correct
18 Correct 5 ms 27224 KB Output is correct
19 Correct 4 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 5 ms 27224 KB Output is correct
22 Correct 4 ms 27252 KB Output is correct
23 Correct 4 ms 27228 KB Output is correct
24 Correct 4 ms 27260 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 4 ms 27224 KB Output is correct
27 Correct 27 ms 28508 KB Output is correct
28 Correct 22 ms 28244 KB Output is correct
29 Correct 35 ms 28416 KB Output is correct
30 Correct 29 ms 28320 KB Output is correct
31 Correct 27 ms 28508 KB Output is correct
32 Correct 23 ms 28184 KB Output is correct
33 Correct 25 ms 28252 KB Output is correct
34 Correct 23 ms 28376 KB Output is correct
35 Correct 135 ms 45392 KB Output is correct
36 Correct 137 ms 45392 KB Output is correct
37 Correct 122 ms 44856 KB Output is correct
38 Correct 126 ms 45140 KB Output is correct
39 Correct 139 ms 45392 KB Output is correct
40 Correct 90 ms 37204 KB Output is correct
41 Correct 72 ms 36884 KB Output is correct
42 Correct 64 ms 34548 KB Output is correct
43 Correct 61 ms 33616 KB Output is correct
44 Correct 83 ms 37520 KB Output is correct
45 Correct 75 ms 37220 KB Output is correct
46 Correct 62 ms 34680 KB Output is correct
47 Correct 62 ms 33724 KB Output is correct
48 Runtime error 2004 ms 262144 KB Execution killed with signal 9
49 Halted 0 ms 0 KB -