답안 #51002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51002 2018-06-15T14:37:14 Z Diuven Rope (JOI17_rope) C++11
100 / 100
1652 ms 81856 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX=1000010, inf=2e9;

int n, m, A[MX];
int C[MX];
int ans[MX];
int idx[MX];

vector<int> G[MX];

void init(int st){
    for(int i=1; i<=m; i++)
        G[i].clear(), C[i]=0;
    for(int i=st; i<=n; i+=2){
        C[A[i]]++; C[A[i+1]]++;
    }
    C[0]=0;
    for(int i=st; i<n; i+=2){
        if(i<1 || A[i]==A[i+1]) continue;
        G[A[i]].push_back(A[i+1]);
        G[A[i+1]].push_back(A[i]);
    }
    iota(idx+1, idx+m+1, 1);
    sort(idx+1, idx+m+1, [](int a, int b){ return C[a]>C[b]; });
}

void solve(int st){
    init(st);
    int adj[MX]={};

    for(int v=1; v<=m; v++){
        int mx=0;
        for(int x:G[v]) adj[x]++;
        for(int x:G[v]){
            mx=max(mx, C[x]-adj[x]);
        }
        for(int i=1; i<=m; i++){
            int x=idx[i];
            if(x!=v && adj[x]==0){
                mx=max(mx, C[x]);
                break;
            }
        }
        for(int x:G[v]) adj[x]--;
        ans[v]=min(ans[v], n-C[v]-mx);
    }
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1; i<=n; i++) cin>>A[i];
    fill(ans+1, ans+m+1, inf);

    solve(0);
    solve(1);
    
    for(int i=1; i<=m; i++) cout<<ans[i]<<'\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 27768 KB Output is correct
2 Correct 30 ms 27884 KB Output is correct
3 Correct 27 ms 27940 KB Output is correct
4 Correct 26 ms 27940 KB Output is correct
5 Correct 25 ms 27940 KB Output is correct
6 Correct 28 ms 27940 KB Output is correct
7 Correct 27 ms 27960 KB Output is correct
8 Correct 28 ms 27960 KB Output is correct
9 Correct 27 ms 28044 KB Output is correct
10 Correct 27 ms 28044 KB Output is correct
11 Correct 25 ms 28044 KB Output is correct
12 Correct 26 ms 28044 KB Output is correct
13 Correct 27 ms 28044 KB Output is correct
14 Correct 25 ms 28044 KB Output is correct
15 Correct 27 ms 28044 KB Output is correct
16 Correct 26 ms 28044 KB Output is correct
17 Correct 27 ms 28044 KB Output is correct
18 Correct 29 ms 28044 KB Output is correct
19 Correct 26 ms 28044 KB Output is correct
20 Correct 25 ms 28044 KB Output is correct
21 Correct 29 ms 28044 KB Output is correct
22 Correct 25 ms 28044 KB Output is correct
23 Correct 31 ms 28044 KB Output is correct
24 Correct 26 ms 28044 KB Output is correct
25 Correct 29 ms 28044 KB Output is correct
26 Correct 31 ms 28044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 27768 KB Output is correct
2 Correct 30 ms 27884 KB Output is correct
3 Correct 27 ms 27940 KB Output is correct
4 Correct 26 ms 27940 KB Output is correct
5 Correct 25 ms 27940 KB Output is correct
6 Correct 28 ms 27940 KB Output is correct
7 Correct 27 ms 27960 KB Output is correct
8 Correct 28 ms 27960 KB Output is correct
9 Correct 27 ms 28044 KB Output is correct
10 Correct 27 ms 28044 KB Output is correct
11 Correct 25 ms 28044 KB Output is correct
12 Correct 26 ms 28044 KB Output is correct
13 Correct 27 ms 28044 KB Output is correct
14 Correct 25 ms 28044 KB Output is correct
15 Correct 27 ms 28044 KB Output is correct
16 Correct 26 ms 28044 KB Output is correct
17 Correct 27 ms 28044 KB Output is correct
18 Correct 29 ms 28044 KB Output is correct
19 Correct 26 ms 28044 KB Output is correct
20 Correct 25 ms 28044 KB Output is correct
21 Correct 29 ms 28044 KB Output is correct
22 Correct 25 ms 28044 KB Output is correct
23 Correct 31 ms 28044 KB Output is correct
24 Correct 26 ms 28044 KB Output is correct
25 Correct 29 ms 28044 KB Output is correct
26 Correct 31 ms 28044 KB Output is correct
27 Correct 34 ms 29008 KB Output is correct
28 Correct 33 ms 29008 KB Output is correct
29 Correct 34 ms 29016 KB Output is correct
30 Correct 34 ms 29016 KB Output is correct
31 Correct 35 ms 29092 KB Output is correct
32 Correct 35 ms 29092 KB Output is correct
33 Correct 34 ms 29092 KB Output is correct
34 Correct 34 ms 29092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 27768 KB Output is correct
2 Correct 30 ms 27884 KB Output is correct
3 Correct 27 ms 27940 KB Output is correct
4 Correct 26 ms 27940 KB Output is correct
5 Correct 25 ms 27940 KB Output is correct
6 Correct 28 ms 27940 KB Output is correct
7 Correct 27 ms 27960 KB Output is correct
8 Correct 28 ms 27960 KB Output is correct
9 Correct 27 ms 28044 KB Output is correct
10 Correct 27 ms 28044 KB Output is correct
11 Correct 25 ms 28044 KB Output is correct
12 Correct 26 ms 28044 KB Output is correct
13 Correct 27 ms 28044 KB Output is correct
14 Correct 25 ms 28044 KB Output is correct
15 Correct 27 ms 28044 KB Output is correct
16 Correct 26 ms 28044 KB Output is correct
17 Correct 27 ms 28044 KB Output is correct
18 Correct 29 ms 28044 KB Output is correct
19 Correct 26 ms 28044 KB Output is correct
20 Correct 25 ms 28044 KB Output is correct
21 Correct 29 ms 28044 KB Output is correct
22 Correct 25 ms 28044 KB Output is correct
23 Correct 31 ms 28044 KB Output is correct
24 Correct 26 ms 28044 KB Output is correct
25 Correct 29 ms 28044 KB Output is correct
26 Correct 31 ms 28044 KB Output is correct
27 Correct 34 ms 29008 KB Output is correct
28 Correct 33 ms 29008 KB Output is correct
29 Correct 34 ms 29016 KB Output is correct
30 Correct 34 ms 29016 KB Output is correct
31 Correct 35 ms 29092 KB Output is correct
32 Correct 35 ms 29092 KB Output is correct
33 Correct 34 ms 29092 KB Output is correct
34 Correct 34 ms 29092 KB Output is correct
35 Correct 41 ms 29092 KB Output is correct
36 Correct 48 ms 29092 KB Output is correct
37 Correct 40 ms 29092 KB Output is correct
38 Correct 52 ms 29092 KB Output is correct
39 Correct 40 ms 29092 KB Output is correct
40 Correct 39 ms 29092 KB Output is correct
41 Correct 35 ms 29092 KB Output is correct
42 Correct 40 ms 29092 KB Output is correct
43 Correct 45 ms 29092 KB Output is correct
44 Correct 36 ms 29092 KB Output is correct
45 Correct 38 ms 29092 KB Output is correct
46 Correct 39 ms 29092 KB Output is correct
47 Correct 38 ms 29092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 27768 KB Output is correct
2 Correct 30 ms 27884 KB Output is correct
3 Correct 27 ms 27940 KB Output is correct
4 Correct 26 ms 27940 KB Output is correct
5 Correct 25 ms 27940 KB Output is correct
6 Correct 28 ms 27940 KB Output is correct
7 Correct 27 ms 27960 KB Output is correct
8 Correct 28 ms 27960 KB Output is correct
9 Correct 27 ms 28044 KB Output is correct
10 Correct 27 ms 28044 KB Output is correct
11 Correct 25 ms 28044 KB Output is correct
12 Correct 26 ms 28044 KB Output is correct
13 Correct 27 ms 28044 KB Output is correct
14 Correct 25 ms 28044 KB Output is correct
15 Correct 27 ms 28044 KB Output is correct
16 Correct 26 ms 28044 KB Output is correct
17 Correct 27 ms 28044 KB Output is correct
18 Correct 29 ms 28044 KB Output is correct
19 Correct 26 ms 28044 KB Output is correct
20 Correct 25 ms 28044 KB Output is correct
21 Correct 29 ms 28044 KB Output is correct
22 Correct 25 ms 28044 KB Output is correct
23 Correct 31 ms 28044 KB Output is correct
24 Correct 26 ms 28044 KB Output is correct
25 Correct 29 ms 28044 KB Output is correct
26 Correct 31 ms 28044 KB Output is correct
27 Correct 34 ms 29008 KB Output is correct
28 Correct 33 ms 29008 KB Output is correct
29 Correct 34 ms 29016 KB Output is correct
30 Correct 34 ms 29016 KB Output is correct
31 Correct 35 ms 29092 KB Output is correct
32 Correct 35 ms 29092 KB Output is correct
33 Correct 34 ms 29092 KB Output is correct
34 Correct 34 ms 29092 KB Output is correct
35 Correct 41 ms 29092 KB Output is correct
36 Correct 48 ms 29092 KB Output is correct
37 Correct 40 ms 29092 KB Output is correct
38 Correct 52 ms 29092 KB Output is correct
39 Correct 40 ms 29092 KB Output is correct
40 Correct 39 ms 29092 KB Output is correct
41 Correct 35 ms 29092 KB Output is correct
42 Correct 40 ms 29092 KB Output is correct
43 Correct 45 ms 29092 KB Output is correct
44 Correct 36 ms 29092 KB Output is correct
45 Correct 38 ms 29092 KB Output is correct
46 Correct 39 ms 29092 KB Output is correct
47 Correct 38 ms 29092 KB Output is correct
48 Correct 174 ms 38528 KB Output is correct
49 Correct 180 ms 38656 KB Output is correct
50 Correct 201 ms 38812 KB Output is correct
51 Correct 177 ms 38812 KB Output is correct
52 Correct 152 ms 38812 KB Output is correct
53 Correct 178 ms 38812 KB Output is correct
54 Correct 157 ms 38812 KB Output is correct
55 Correct 169 ms 38812 KB Output is correct
56 Correct 173 ms 38812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 27768 KB Output is correct
2 Correct 30 ms 27884 KB Output is correct
3 Correct 27 ms 27940 KB Output is correct
4 Correct 26 ms 27940 KB Output is correct
5 Correct 25 ms 27940 KB Output is correct
6 Correct 28 ms 27940 KB Output is correct
7 Correct 27 ms 27960 KB Output is correct
8 Correct 28 ms 27960 KB Output is correct
9 Correct 27 ms 28044 KB Output is correct
10 Correct 27 ms 28044 KB Output is correct
11 Correct 25 ms 28044 KB Output is correct
12 Correct 26 ms 28044 KB Output is correct
13 Correct 27 ms 28044 KB Output is correct
14 Correct 25 ms 28044 KB Output is correct
15 Correct 27 ms 28044 KB Output is correct
16 Correct 26 ms 28044 KB Output is correct
17 Correct 27 ms 28044 KB Output is correct
18 Correct 29 ms 28044 KB Output is correct
19 Correct 26 ms 28044 KB Output is correct
20 Correct 25 ms 28044 KB Output is correct
21 Correct 29 ms 28044 KB Output is correct
22 Correct 25 ms 28044 KB Output is correct
23 Correct 31 ms 28044 KB Output is correct
24 Correct 26 ms 28044 KB Output is correct
25 Correct 29 ms 28044 KB Output is correct
26 Correct 31 ms 28044 KB Output is correct
27 Correct 34 ms 29008 KB Output is correct
28 Correct 33 ms 29008 KB Output is correct
29 Correct 34 ms 29016 KB Output is correct
30 Correct 34 ms 29016 KB Output is correct
31 Correct 35 ms 29092 KB Output is correct
32 Correct 35 ms 29092 KB Output is correct
33 Correct 34 ms 29092 KB Output is correct
34 Correct 34 ms 29092 KB Output is correct
35 Correct 41 ms 29092 KB Output is correct
36 Correct 48 ms 29092 KB Output is correct
37 Correct 40 ms 29092 KB Output is correct
38 Correct 52 ms 29092 KB Output is correct
39 Correct 40 ms 29092 KB Output is correct
40 Correct 39 ms 29092 KB Output is correct
41 Correct 35 ms 29092 KB Output is correct
42 Correct 40 ms 29092 KB Output is correct
43 Correct 45 ms 29092 KB Output is correct
44 Correct 36 ms 29092 KB Output is correct
45 Correct 38 ms 29092 KB Output is correct
46 Correct 39 ms 29092 KB Output is correct
47 Correct 38 ms 29092 KB Output is correct
48 Correct 174 ms 38528 KB Output is correct
49 Correct 180 ms 38656 KB Output is correct
50 Correct 201 ms 38812 KB Output is correct
51 Correct 177 ms 38812 KB Output is correct
52 Correct 152 ms 38812 KB Output is correct
53 Correct 178 ms 38812 KB Output is correct
54 Correct 157 ms 38812 KB Output is correct
55 Correct 169 ms 38812 KB Output is correct
56 Correct 173 ms 38812 KB Output is correct
57 Correct 1652 ms 81856 KB Output is correct
58 Correct 1264 ms 81856 KB Output is correct
59 Correct 1295 ms 81856 KB Output is correct
60 Correct 1493 ms 81856 KB Output is correct
61 Correct 1478 ms 81856 KB Output is correct
62 Correct 486 ms 81856 KB Output is correct
63 Correct 845 ms 81856 KB Output is correct
64 Correct 655 ms 81856 KB Output is correct
65 Correct 351 ms 81856 KB Output is correct