답안 #128690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128690 2019-07-11T08:29:01 Z 송준혁(#3162) Rope (JOI17_rope) C++14
80 / 100
2500 ms 132988 KB
#include <bits/stdc++.h>
using namespace std;

int N, M;
int A[1010101];
vector<int> O[1010101], E[1010101];
int cnt[1010101];
int T[4040404];

void init(int id, int s, int e){
    if (s == e){
        T[id] = cnt[s];
        return;
    }
    int mid = (s+e)/2;
    init(id*2, s, mid);
    init(id*2+1, mid+1, e);
    T[id] = max(T[id*2], T[id*2+1]);
}

void update(int id, int s, int e, int t, int v){
    if (e < t || t < s) return;
    if (s == e){
        T[id] += v;
        return;
    }
    int mid = (s+e)/2;
    update(id*2, s, mid, t, v);
    update(id*2+1, mid+1, e, t, v);
    T[id] = max(T[id*2], T[id*2+1]);
}

int RMQ(int id, int s, int e, int ts, int te){
    if (e < ts || te < s) return 0;
    if (ts <= s && e <= te) return T[id];
    int mid = (s+e)/2;
    return max(RMQ(id*2, s, mid, ts, te), RMQ(id*2+1, mid+1, e, ts, te));
}

int main(){
    scanf("%d %d", &N, &M);
    for (int i=1; i<=N; i++){
        scanf("%d", &A[i]);
        cnt[A[i]]++;
    }
    for (int i=1; i<=M; i++){
        E[i].reserve(cnt[i]);
        O[i].reserve(cnt[i]);
    }
    for (int i=1; i<N; i++){
        if (A[i] == A[i+1]) continue;
        if (i & 1){
            E[A[i]].push_back(A[i+1]);
            E[A[i+1]].push_back(A[i]);
        }
        else{
            O[A[i]].push_back(A[i+1]);
            O[A[i+1]].push_back(A[i]);
        }
    }
    init(1, 1, M);
    for (int i=1; i<=M; i++){
        for (int x : O[i]) update(1, 1, M, x, -1);
        int oret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
        for (int x : O[i]) update(1, 1, M, x, 1);

        for (int x : E[i]) update(1, 1, M, x, -1);
        int eret = cnt[i] + max(RMQ(1, 1, M, 1, i-1), RMQ(1, 1, M, i+1, M));
        for (int x : E[i]) update(1, 1, M, x, 1);
        printf("%d\n", N - max(oret, eret));
    }
    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:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47736 KB Output is correct
2 Correct 45 ms 47864 KB Output is correct
3 Correct 45 ms 47736 KB Output is correct
4 Correct 56 ms 47736 KB Output is correct
5 Correct 55 ms 47736 KB Output is correct
6 Correct 55 ms 47864 KB Output is correct
7 Correct 47 ms 47824 KB Output is correct
8 Correct 45 ms 47740 KB Output is correct
9 Correct 44 ms 47736 KB Output is correct
10 Correct 45 ms 47736 KB Output is correct
11 Correct 45 ms 47708 KB Output is correct
12 Correct 45 ms 47864 KB Output is correct
13 Correct 45 ms 47764 KB Output is correct
14 Correct 44 ms 47736 KB Output is correct
15 Correct 45 ms 47736 KB Output is correct
16 Correct 46 ms 47852 KB Output is correct
17 Correct 44 ms 47716 KB Output is correct
18 Correct 45 ms 47864 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 44 ms 47736 KB Output is correct
21 Correct 45 ms 47864 KB Output is correct
22 Correct 49 ms 47728 KB Output is correct
23 Correct 46 ms 47864 KB Output is correct
24 Correct 46 ms 47736 KB Output is correct
25 Correct 45 ms 47736 KB Output is correct
26 Correct 45 ms 47736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47736 KB Output is correct
2 Correct 45 ms 47864 KB Output is correct
3 Correct 45 ms 47736 KB Output is correct
4 Correct 56 ms 47736 KB Output is correct
5 Correct 55 ms 47736 KB Output is correct
6 Correct 55 ms 47864 KB Output is correct
7 Correct 47 ms 47824 KB Output is correct
8 Correct 45 ms 47740 KB Output is correct
9 Correct 44 ms 47736 KB Output is correct
10 Correct 45 ms 47736 KB Output is correct
11 Correct 45 ms 47708 KB Output is correct
12 Correct 45 ms 47864 KB Output is correct
13 Correct 45 ms 47764 KB Output is correct
14 Correct 44 ms 47736 KB Output is correct
15 Correct 45 ms 47736 KB Output is correct
16 Correct 46 ms 47852 KB Output is correct
17 Correct 44 ms 47716 KB Output is correct
18 Correct 45 ms 47864 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 44 ms 47736 KB Output is correct
21 Correct 45 ms 47864 KB Output is correct
22 Correct 49 ms 47728 KB Output is correct
23 Correct 46 ms 47864 KB Output is correct
24 Correct 46 ms 47736 KB Output is correct
25 Correct 45 ms 47736 KB Output is correct
26 Correct 45 ms 47736 KB Output is correct
27 Correct 72 ms 49248 KB Output is correct
28 Correct 67 ms 49016 KB Output is correct
29 Correct 71 ms 49144 KB Output is correct
30 Correct 65 ms 49084 KB Output is correct
31 Correct 72 ms 49180 KB Output is correct
32 Correct 62 ms 49144 KB Output is correct
33 Correct 70 ms 49144 KB Output is correct
34 Correct 65 ms 49020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47736 KB Output is correct
2 Correct 45 ms 47864 KB Output is correct
3 Correct 45 ms 47736 KB Output is correct
4 Correct 56 ms 47736 KB Output is correct
5 Correct 55 ms 47736 KB Output is correct
6 Correct 55 ms 47864 KB Output is correct
7 Correct 47 ms 47824 KB Output is correct
8 Correct 45 ms 47740 KB Output is correct
9 Correct 44 ms 47736 KB Output is correct
10 Correct 45 ms 47736 KB Output is correct
11 Correct 45 ms 47708 KB Output is correct
12 Correct 45 ms 47864 KB Output is correct
13 Correct 45 ms 47764 KB Output is correct
14 Correct 44 ms 47736 KB Output is correct
15 Correct 45 ms 47736 KB Output is correct
16 Correct 46 ms 47852 KB Output is correct
17 Correct 44 ms 47716 KB Output is correct
18 Correct 45 ms 47864 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 44 ms 47736 KB Output is correct
21 Correct 45 ms 47864 KB Output is correct
22 Correct 49 ms 47728 KB Output is correct
23 Correct 46 ms 47864 KB Output is correct
24 Correct 46 ms 47736 KB Output is correct
25 Correct 45 ms 47736 KB Output is correct
26 Correct 45 ms 47736 KB Output is correct
27 Correct 72 ms 49248 KB Output is correct
28 Correct 67 ms 49016 KB Output is correct
29 Correct 71 ms 49144 KB Output is correct
30 Correct 65 ms 49084 KB Output is correct
31 Correct 72 ms 49180 KB Output is correct
32 Correct 62 ms 49144 KB Output is correct
33 Correct 70 ms 49144 KB Output is correct
34 Correct 65 ms 49020 KB Output is correct
35 Correct 105 ms 49200 KB Output is correct
36 Correct 106 ms 49228 KB Output is correct
37 Correct 104 ms 49272 KB Output is correct
38 Correct 105 ms 49272 KB Output is correct
39 Correct 107 ms 49144 KB Output is correct
40 Correct 110 ms 49144 KB Output is correct
41 Correct 99 ms 49252 KB Output is correct
42 Correct 96 ms 49144 KB Output is correct
43 Correct 96 ms 49260 KB Output is correct
44 Correct 99 ms 49400 KB Output is correct
45 Correct 99 ms 49144 KB Output is correct
46 Correct 101 ms 49144 KB Output is correct
47 Correct 97 ms 49144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47736 KB Output is correct
2 Correct 45 ms 47864 KB Output is correct
3 Correct 45 ms 47736 KB Output is correct
4 Correct 56 ms 47736 KB Output is correct
5 Correct 55 ms 47736 KB Output is correct
6 Correct 55 ms 47864 KB Output is correct
7 Correct 47 ms 47824 KB Output is correct
8 Correct 45 ms 47740 KB Output is correct
9 Correct 44 ms 47736 KB Output is correct
10 Correct 45 ms 47736 KB Output is correct
11 Correct 45 ms 47708 KB Output is correct
12 Correct 45 ms 47864 KB Output is correct
13 Correct 45 ms 47764 KB Output is correct
14 Correct 44 ms 47736 KB Output is correct
15 Correct 45 ms 47736 KB Output is correct
16 Correct 46 ms 47852 KB Output is correct
17 Correct 44 ms 47716 KB Output is correct
18 Correct 45 ms 47864 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 44 ms 47736 KB Output is correct
21 Correct 45 ms 47864 KB Output is correct
22 Correct 49 ms 47728 KB Output is correct
23 Correct 46 ms 47864 KB Output is correct
24 Correct 46 ms 47736 KB Output is correct
25 Correct 45 ms 47736 KB Output is correct
26 Correct 45 ms 47736 KB Output is correct
27 Correct 72 ms 49248 KB Output is correct
28 Correct 67 ms 49016 KB Output is correct
29 Correct 71 ms 49144 KB Output is correct
30 Correct 65 ms 49084 KB Output is correct
31 Correct 72 ms 49180 KB Output is correct
32 Correct 62 ms 49144 KB Output is correct
33 Correct 70 ms 49144 KB Output is correct
34 Correct 65 ms 49020 KB Output is correct
35 Correct 105 ms 49200 KB Output is correct
36 Correct 106 ms 49228 KB Output is correct
37 Correct 104 ms 49272 KB Output is correct
38 Correct 105 ms 49272 KB Output is correct
39 Correct 107 ms 49144 KB Output is correct
40 Correct 110 ms 49144 KB Output is correct
41 Correct 99 ms 49252 KB Output is correct
42 Correct 96 ms 49144 KB Output is correct
43 Correct 96 ms 49260 KB Output is correct
44 Correct 99 ms 49400 KB Output is correct
45 Correct 99 ms 49144 KB Output is correct
46 Correct 101 ms 49144 KB Output is correct
47 Correct 97 ms 49144 KB Output is correct
48 Correct 815 ms 60196 KB Output is correct
49 Correct 813 ms 60320 KB Output is correct
50 Correct 822 ms 60252 KB Output is correct
51 Correct 752 ms 60008 KB Output is correct
52 Correct 744 ms 60180 KB Output is correct
53 Correct 777 ms 60252 KB Output is correct
54 Correct 771 ms 60216 KB Output is correct
55 Correct 772 ms 60248 KB Output is correct
56 Correct 764 ms 60152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47736 KB Output is correct
2 Correct 45 ms 47864 KB Output is correct
3 Correct 45 ms 47736 KB Output is correct
4 Correct 56 ms 47736 KB Output is correct
5 Correct 55 ms 47736 KB Output is correct
6 Correct 55 ms 47864 KB Output is correct
7 Correct 47 ms 47824 KB Output is correct
8 Correct 45 ms 47740 KB Output is correct
9 Correct 44 ms 47736 KB Output is correct
10 Correct 45 ms 47736 KB Output is correct
11 Correct 45 ms 47708 KB Output is correct
12 Correct 45 ms 47864 KB Output is correct
13 Correct 45 ms 47764 KB Output is correct
14 Correct 44 ms 47736 KB Output is correct
15 Correct 45 ms 47736 KB Output is correct
16 Correct 46 ms 47852 KB Output is correct
17 Correct 44 ms 47716 KB Output is correct
18 Correct 45 ms 47864 KB Output is correct
19 Correct 45 ms 47736 KB Output is correct
20 Correct 44 ms 47736 KB Output is correct
21 Correct 45 ms 47864 KB Output is correct
22 Correct 49 ms 47728 KB Output is correct
23 Correct 46 ms 47864 KB Output is correct
24 Correct 46 ms 47736 KB Output is correct
25 Correct 45 ms 47736 KB Output is correct
26 Correct 45 ms 47736 KB Output is correct
27 Correct 72 ms 49248 KB Output is correct
28 Correct 67 ms 49016 KB Output is correct
29 Correct 71 ms 49144 KB Output is correct
30 Correct 65 ms 49084 KB Output is correct
31 Correct 72 ms 49180 KB Output is correct
32 Correct 62 ms 49144 KB Output is correct
33 Correct 70 ms 49144 KB Output is correct
34 Correct 65 ms 49020 KB Output is correct
35 Correct 105 ms 49200 KB Output is correct
36 Correct 106 ms 49228 KB Output is correct
37 Correct 104 ms 49272 KB Output is correct
38 Correct 105 ms 49272 KB Output is correct
39 Correct 107 ms 49144 KB Output is correct
40 Correct 110 ms 49144 KB Output is correct
41 Correct 99 ms 49252 KB Output is correct
42 Correct 96 ms 49144 KB Output is correct
43 Correct 96 ms 49260 KB Output is correct
44 Correct 99 ms 49400 KB Output is correct
45 Correct 99 ms 49144 KB Output is correct
46 Correct 101 ms 49144 KB Output is correct
47 Correct 97 ms 49144 KB Output is correct
48 Correct 815 ms 60196 KB Output is correct
49 Correct 813 ms 60320 KB Output is correct
50 Correct 822 ms 60252 KB Output is correct
51 Correct 752 ms 60008 KB Output is correct
52 Correct 744 ms 60180 KB Output is correct
53 Correct 777 ms 60252 KB Output is correct
54 Correct 771 ms 60216 KB Output is correct
55 Correct 772 ms 60248 KB Output is correct
56 Correct 764 ms 60152 KB Output is correct
57 Execution timed out 2542 ms 132988 KB Time limit exceeded
58 Halted 0 ms 0 KB -