Submission #257545

# Submission time Handle Problem Language Result Execution time Memory
257545 2020-08-04T11:52:57 Z anonymous Global Warming (CEOI18_glo) C++14
100 / 100
91 ms 5844 KB
#include <iostream>
#define MAXN 200005
using namespace std;
int N, X, Ans, A[MAXN], Op[MAXN][2];
int dp[MAXN], dp2[MAXN]; //min height for i length in prefix, max height for i length in suffix

int main() {
    //freopen("gloin.txt","r",stdin);
    scanf("%d %d",&N,&X);
    for (int i=1; i<=N; i++) {
        scanf("%d",&A[i]);
        dp[i] = 2e9 + 1;
    }
    dp2[0] = 2e9 + 1;

    for (int i=1; i <= N; i++) {
        int lo = 0, hi = N;
        while (lo + 1 != hi) {
            int mid = (lo + hi) >> 1;
            if (dp[mid] >= A[i]) {hi = mid;}
            else {lo = mid;}
        }
        Op[i][0] = lo+1, Op[i][1] = dp[lo+1];
        dp[lo+1] = A[i];
        Ans = max(Ans, lo+1);
    }

    for (int i=N; i >= 1; i--) {
        int lo = 0, hi = N;
        while (lo + 1 != hi) {
            int mid = (lo + hi) >> 1;
            if (dp2[mid] <= A[i]) {hi = mid;}
            else {lo = mid;}
        }
        dp2[lo+1] = A[i];
        dp[Op[i][0]] = Op[i][1];
        int lo2 = 0, hi2 = N;
        while (lo2 + 1 != hi2) {
            int mid = (lo2 + hi2) >> 1;
            if (dp[mid] >= A[i] + X) {hi2 = mid;}
            else {lo2 = mid;}
        }
        Ans = max(Ans, lo2 + lo + 1);
    }

    printf("%d", Ans);
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&X);
     ~~~~~^~~~~~~~~~~~~~~
glo.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&A[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 416 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 3492 KB Output is correct
2 Correct 82 ms 3580 KB Output is correct
3 Correct 82 ms 3580 KB Output is correct
4 Correct 82 ms 3576 KB Output is correct
5 Correct 62 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1152 KB Output is correct
2 Correct 20 ms 1280 KB Output is correct
3 Correct 27 ms 1280 KB Output is correct
4 Correct 16 ms 1280 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 16 ms 1280 KB Output is correct
7 Correct 18 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2044 KB Output is correct
2 Correct 37 ms 2816 KB Output is correct
3 Correct 74 ms 5368 KB Output is correct
4 Correct 66 ms 5112 KB Output is correct
5 Correct 32 ms 2680 KB Output is correct
6 Correct 52 ms 4856 KB Output is correct
7 Correct 56 ms 5496 KB Output is correct
8 Correct 30 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 416 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 84 ms 3492 KB Output is correct
28 Correct 82 ms 3580 KB Output is correct
29 Correct 82 ms 3580 KB Output is correct
30 Correct 82 ms 3576 KB Output is correct
31 Correct 62 ms 3960 KB Output is correct
32 Correct 20 ms 1152 KB Output is correct
33 Correct 20 ms 1280 KB Output is correct
34 Correct 27 ms 1280 KB Output is correct
35 Correct 16 ms 1280 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 16 ms 1280 KB Output is correct
38 Correct 18 ms 1280 KB Output is correct
39 Correct 38 ms 2044 KB Output is correct
40 Correct 37 ms 2816 KB Output is correct
41 Correct 74 ms 5368 KB Output is correct
42 Correct 66 ms 5112 KB Output is correct
43 Correct 32 ms 2680 KB Output is correct
44 Correct 52 ms 4856 KB Output is correct
45 Correct 56 ms 5496 KB Output is correct
46 Correct 30 ms 2936 KB Output is correct
47 Correct 41 ms 2920 KB Output is correct
48 Correct 41 ms 2816 KB Output is correct
49 Correct 91 ms 5360 KB Output is correct
50 Correct 68 ms 4984 KB Output is correct
51 Correct 49 ms 3892 KB Output is correct
52 Correct 65 ms 5112 KB Output is correct
53 Correct 55 ms 5112 KB Output is correct
54 Correct 59 ms 5844 KB Output is correct
55 Correct 76 ms 5368 KB Output is correct