답안 #70181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70181 2018-08-22T13:02:53 Z model_code Global Warming (CEOI18_glo) C++17
100 / 100
100 ms 10804 KB
// Patryk Czajka
// O(n*logn)

#include <cstdio>


inline int max(int a, int b) {
    return a > b ? a : b;
}

int n, X, res;
const int maxN = 2e5+10;


int dp_max[maxN];
int dp_min[maxN];
int mx_i, mn_i;

int find(int* dp, int i, int val) {
    int a = -1, b = i, avg;
    while(b - a > 1) {
        avg = (a + b) / 2;
        if(dp[avg] < val) a = avg;
        else b = avg;
    }
    return b;
}

int add(int* dp, int &i, int val) {
    int b = find(dp, i, val);
    dp[b] = val;
    i = max(i, b + 1);
    return b;
}

void count(int left) {
    if(left == 0)
        return;

    int val;
    scanf("%d", &val);
    int b_here = add(dp_max, mx_i, val);

    count(left - 1);

    res = max(b_here + find(dp_min, mn_i, -val+X) + 1, res);
    add(dp_min, mn_i, -val);
}


int main() {
    scanf("%d%d", &n, &X);
    count(n);
    printf("%d\n", res);
}

Compilation message

glo.cpp: In function 'void count(int)':
glo.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &val);
     ~~~~~^~~~~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &X);
     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 3 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 560 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 3 ms 560 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 3 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 560 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 3 ms 560 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 9988 KB Output is correct
2 Correct 97 ms 9988 KB Output is correct
3 Correct 79 ms 9988 KB Output is correct
4 Correct 76 ms 9988 KB Output is correct
5 Correct 90 ms 10780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 10780 KB Output is correct
2 Correct 23 ms 10780 KB Output is correct
3 Correct 21 ms 10780 KB Output is correct
4 Correct 27 ms 10780 KB Output is correct
5 Correct 3 ms 10780 KB Output is correct
6 Correct 21 ms 10780 KB Output is correct
7 Correct 20 ms 10780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10780 KB Output is correct
2 Correct 38 ms 10780 KB Output is correct
3 Correct 88 ms 10780 KB Output is correct
4 Correct 85 ms 10804 KB Output is correct
5 Correct 41 ms 10804 KB Output is correct
6 Correct 70 ms 10804 KB Output is correct
7 Correct 82 ms 10804 KB Output is correct
8 Correct 38 ms 10804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 2 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 3 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 560 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 3 ms 560 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 85 ms 9988 KB Output is correct
28 Correct 97 ms 9988 KB Output is correct
29 Correct 79 ms 9988 KB Output is correct
30 Correct 76 ms 9988 KB Output is correct
31 Correct 90 ms 10780 KB Output is correct
32 Correct 21 ms 10780 KB Output is correct
33 Correct 23 ms 10780 KB Output is correct
34 Correct 21 ms 10780 KB Output is correct
35 Correct 27 ms 10780 KB Output is correct
36 Correct 3 ms 10780 KB Output is correct
37 Correct 21 ms 10780 KB Output is correct
38 Correct 20 ms 10780 KB Output is correct
39 Correct 42 ms 10780 KB Output is correct
40 Correct 38 ms 10780 KB Output is correct
41 Correct 88 ms 10780 KB Output is correct
42 Correct 85 ms 10804 KB Output is correct
43 Correct 41 ms 10804 KB Output is correct
44 Correct 70 ms 10804 KB Output is correct
45 Correct 82 ms 10804 KB Output is correct
46 Correct 38 ms 10804 KB Output is correct
47 Correct 45 ms 10804 KB Output is correct
48 Correct 37 ms 10804 KB Output is correct
49 Correct 76 ms 10804 KB Output is correct
50 Correct 88 ms 10804 KB Output is correct
51 Correct 74 ms 10804 KB Output is correct
52 Correct 100 ms 10804 KB Output is correct
53 Correct 82 ms 10804 KB Output is correct
54 Correct 88 ms 10804 KB Output is correct
55 Correct 72 ms 10804 KB Output is correct