답안 #196946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
196946 2020-01-17T18:52:23 Z Akashi Rope (JOI17_rope) C++14
100 / 100
1193 ms 92780 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

vector <pair <int, int> > col;
vector <int> v[N];

int n, m;
int ans[N], f[N], x[N], cnt[N];

inline int calc(int x, int y){
    return n - f[x] - f[y] + cnt[y];
}

void solve(int st, int dr){
    for(int i = st; i < dr ; i += 2){
        if(x[i] != x[i + 1]){
            v[x[i]].push_back(x[i + 1]);
            v[x[i + 1]].push_back(x[i]);
        }
    }

    for(int i = 1; i <= m ; ++i){
        for(auto it : v[i]) ++cnt[it];

        for(auto it : v[i]) ans[i] = min(ans[i], calc(i, it));

        int j = m - 1;
        while(j >= 0 && (cnt[col[j].second] || col[j].second == i)) --j;
        if(j >= 0) ans[i] = min(ans[i], calc(i, col[j].second));

        for(auto it : v[i]) --cnt[it];
    }

    for(int i = 1; i <= m ; ++i) v[i].clear();
}

int main()
{
    scanf("%d%d", &n, &m);

    for(int i = 1; i <= m ; ++i) ans[i] = n;

    for(int i = 1; i <= n ; ++i){
        scanf("%d", &x[i]);
        ++f[x[i]];
        --ans[x[i]];
    }

    for(int i = 1; i <= m ; ++i) col.push_back({f[i], i});
    sort(col.begin(), col.end());

    solve(1, n - 1);
    solve(2, n);

    for(int i = 1; i <= m ; ++i)
        printf("%d\n", ans[i]);

    return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
rope.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 21 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 24 ms 23928 KB Output is correct
12 Correct 27 ms 23800 KB Output is correct
13 Correct 24 ms 23800 KB Output is correct
14 Correct 27 ms 23800 KB Output is correct
15 Correct 28 ms 23800 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 26 ms 23864 KB Output is correct
18 Correct 27 ms 23848 KB Output is correct
19 Correct 28 ms 23800 KB Output is correct
20 Correct 27 ms 23800 KB Output is correct
21 Correct 28 ms 23800 KB Output is correct
22 Correct 24 ms 23800 KB Output is correct
23 Correct 28 ms 23800 KB Output is correct
24 Correct 24 ms 23800 KB Output is correct
25 Correct 24 ms 23800 KB Output is correct
26 Correct 24 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 21 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 24 ms 23928 KB Output is correct
12 Correct 27 ms 23800 KB Output is correct
13 Correct 24 ms 23800 KB Output is correct
14 Correct 27 ms 23800 KB Output is correct
15 Correct 28 ms 23800 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 26 ms 23864 KB Output is correct
18 Correct 27 ms 23848 KB Output is correct
19 Correct 28 ms 23800 KB Output is correct
20 Correct 27 ms 23800 KB Output is correct
21 Correct 28 ms 23800 KB Output is correct
22 Correct 24 ms 23800 KB Output is correct
23 Correct 28 ms 23800 KB Output is correct
24 Correct 24 ms 23800 KB Output is correct
25 Correct 24 ms 23800 KB Output is correct
26 Correct 24 ms 23800 KB Output is correct
27 Correct 40 ms 25008 KB Output is correct
28 Correct 37 ms 24944 KB Output is correct
29 Correct 37 ms 24952 KB Output is correct
30 Correct 36 ms 24824 KB Output is correct
31 Correct 37 ms 25208 KB Output is correct
32 Correct 36 ms 24952 KB Output is correct
33 Correct 37 ms 24952 KB Output is correct
34 Correct 31 ms 24924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 21 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 24 ms 23928 KB Output is correct
12 Correct 27 ms 23800 KB Output is correct
13 Correct 24 ms 23800 KB Output is correct
14 Correct 27 ms 23800 KB Output is correct
15 Correct 28 ms 23800 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 26 ms 23864 KB Output is correct
18 Correct 27 ms 23848 KB Output is correct
19 Correct 28 ms 23800 KB Output is correct
20 Correct 27 ms 23800 KB Output is correct
21 Correct 28 ms 23800 KB Output is correct
22 Correct 24 ms 23800 KB Output is correct
23 Correct 28 ms 23800 KB Output is correct
24 Correct 24 ms 23800 KB Output is correct
25 Correct 24 ms 23800 KB Output is correct
26 Correct 24 ms 23800 KB Output is correct
27 Correct 40 ms 25008 KB Output is correct
28 Correct 37 ms 24944 KB Output is correct
29 Correct 37 ms 24952 KB Output is correct
30 Correct 36 ms 24824 KB Output is correct
31 Correct 37 ms 25208 KB Output is correct
32 Correct 36 ms 24952 KB Output is correct
33 Correct 37 ms 24952 KB Output is correct
34 Correct 31 ms 24924 KB Output is correct
35 Correct 40 ms 25300 KB Output is correct
36 Correct 39 ms 25208 KB Output is correct
37 Correct 39 ms 25108 KB Output is correct
38 Correct 39 ms 25144 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 39 ms 25208 KB Output is correct
41 Correct 39 ms 25224 KB Output is correct
42 Correct 62 ms 25336 KB Output is correct
43 Correct 40 ms 25208 KB Output is correct
44 Correct 39 ms 25184 KB Output is correct
45 Correct 40 ms 25208 KB Output is correct
46 Correct 39 ms 25180 KB Output is correct
47 Correct 40 ms 25208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 21 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 24 ms 23928 KB Output is correct
12 Correct 27 ms 23800 KB Output is correct
13 Correct 24 ms 23800 KB Output is correct
14 Correct 27 ms 23800 KB Output is correct
15 Correct 28 ms 23800 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 26 ms 23864 KB Output is correct
18 Correct 27 ms 23848 KB Output is correct
19 Correct 28 ms 23800 KB Output is correct
20 Correct 27 ms 23800 KB Output is correct
21 Correct 28 ms 23800 KB Output is correct
22 Correct 24 ms 23800 KB Output is correct
23 Correct 28 ms 23800 KB Output is correct
24 Correct 24 ms 23800 KB Output is correct
25 Correct 24 ms 23800 KB Output is correct
26 Correct 24 ms 23800 KB Output is correct
27 Correct 40 ms 25008 KB Output is correct
28 Correct 37 ms 24944 KB Output is correct
29 Correct 37 ms 24952 KB Output is correct
30 Correct 36 ms 24824 KB Output is correct
31 Correct 37 ms 25208 KB Output is correct
32 Correct 36 ms 24952 KB Output is correct
33 Correct 37 ms 24952 KB Output is correct
34 Correct 31 ms 24924 KB Output is correct
35 Correct 40 ms 25300 KB Output is correct
36 Correct 39 ms 25208 KB Output is correct
37 Correct 39 ms 25108 KB Output is correct
38 Correct 39 ms 25144 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 39 ms 25208 KB Output is correct
41 Correct 39 ms 25224 KB Output is correct
42 Correct 62 ms 25336 KB Output is correct
43 Correct 40 ms 25208 KB Output is correct
44 Correct 39 ms 25184 KB Output is correct
45 Correct 40 ms 25208 KB Output is correct
46 Correct 39 ms 25180 KB Output is correct
47 Correct 40 ms 25208 KB Output is correct
48 Correct 217 ms 39012 KB Output is correct
49 Correct 216 ms 39092 KB Output is correct
50 Correct 213 ms 39032 KB Output is correct
51 Correct 195 ms 38524 KB Output is correct
52 Correct 186 ms 37308 KB Output is correct
53 Correct 193 ms 38204 KB Output is correct
54 Correct 196 ms 37156 KB Output is correct
55 Correct 188 ms 37016 KB Output is correct
56 Correct 185 ms 36736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB Output is correct
2 Correct 24 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 21 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23800 KB Output is correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 24 ms 23928 KB Output is correct
12 Correct 27 ms 23800 KB Output is correct
13 Correct 24 ms 23800 KB Output is correct
14 Correct 27 ms 23800 KB Output is correct
15 Correct 28 ms 23800 KB Output is correct
16 Correct 24 ms 23800 KB Output is correct
17 Correct 26 ms 23864 KB Output is correct
18 Correct 27 ms 23848 KB Output is correct
19 Correct 28 ms 23800 KB Output is correct
20 Correct 27 ms 23800 KB Output is correct
21 Correct 28 ms 23800 KB Output is correct
22 Correct 24 ms 23800 KB Output is correct
23 Correct 28 ms 23800 KB Output is correct
24 Correct 24 ms 23800 KB Output is correct
25 Correct 24 ms 23800 KB Output is correct
26 Correct 24 ms 23800 KB Output is correct
27 Correct 40 ms 25008 KB Output is correct
28 Correct 37 ms 24944 KB Output is correct
29 Correct 37 ms 24952 KB Output is correct
30 Correct 36 ms 24824 KB Output is correct
31 Correct 37 ms 25208 KB Output is correct
32 Correct 36 ms 24952 KB Output is correct
33 Correct 37 ms 24952 KB Output is correct
34 Correct 31 ms 24924 KB Output is correct
35 Correct 40 ms 25300 KB Output is correct
36 Correct 39 ms 25208 KB Output is correct
37 Correct 39 ms 25108 KB Output is correct
38 Correct 39 ms 25144 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 39 ms 25208 KB Output is correct
41 Correct 39 ms 25224 KB Output is correct
42 Correct 62 ms 25336 KB Output is correct
43 Correct 40 ms 25208 KB Output is correct
44 Correct 39 ms 25184 KB Output is correct
45 Correct 40 ms 25208 KB Output is correct
46 Correct 39 ms 25180 KB Output is correct
47 Correct 40 ms 25208 KB Output is correct
48 Correct 217 ms 39012 KB Output is correct
49 Correct 216 ms 39092 KB Output is correct
50 Correct 213 ms 39032 KB Output is correct
51 Correct 195 ms 38524 KB Output is correct
52 Correct 186 ms 37308 KB Output is correct
53 Correct 193 ms 38204 KB Output is correct
54 Correct 196 ms 37156 KB Output is correct
55 Correct 188 ms 37016 KB Output is correct
56 Correct 185 ms 36736 KB Output is correct
57 Correct 1193 ms 92780 KB Output is correct
58 Correct 963 ms 69328 KB Output is correct
59 Correct 980 ms 69108 KB Output is correct
60 Correct 1106 ms 74940 KB Output is correct
61 Correct 1018 ms 75216 KB Output is correct
62 Correct 470 ms 54888 KB Output is correct
63 Correct 675 ms 61404 KB Output is correct
64 Correct 574 ms 57184 KB Output is correct
65 Correct 306 ms 46756 KB Output is correct