Submission #1104763

# Submission time Handle Problem Language Result Execution time Memory
1104763 2024-10-24T10:43:12 Z KasymK Global Warming (CEOI18_glo) C++17
100 / 100
50 ms 5456 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 2e5+5;
const int INF = 1e9;
int cep[N], sag[N], v[N], dp[N];

int main(){
    int n, x; scanf("%d%d", &n, &x);
    for(int i = 0; i < n; ++i){
        int x; scanf("%d", &x);
        v[i] = x;
    }
    auto reload = [&]() {
        for(int i = 0; i < n; ++i)
            dp[i] = INF;
    };
    int answer = 0;
    reload();
    for(int i = 0; i < n; ++i){
        int j = lower_bound(dp, dp+n, v[i])-dp;
        dp[j] = v[i], cep[i] = j+1;
    }
    reload();
    for(int i = n-1; i >= 0; --i){
        int j = lower_bound(dp, dp+n, -v[i]+x)-dp;
        sag[i] = j;
        j = lower_bound(dp, dp+n, -v[i])-dp;
        dp[j] = -v[i];
    }
    for(int i = 0; i < n; ++i)
        umax(answer, cep[i]+sag[i]);
    printf("%d\n", answer);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:20:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     int n, x; scanf("%d%d", &n, &x);
      |               ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:22:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         int x; scanf("%d", &x);
      |                ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2560 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3400 KB Output is correct
2 Correct 44 ms 5112 KB Output is correct
3 Correct 46 ms 5200 KB Output is correct
4 Correct 43 ms 5448 KB Output is correct
5 Correct 41 ms 4280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3040 KB Output is correct
2 Correct 11 ms 3320 KB Output is correct
3 Correct 11 ms 3152 KB Output is correct
4 Correct 9 ms 3152 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 10 ms 3020 KB Output is correct
7 Correct 11 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3664 KB Output is correct
2 Correct 21 ms 3920 KB Output is correct
3 Correct 50 ms 5320 KB Output is correct
4 Correct 34 ms 4732 KB Output is correct
5 Correct 18 ms 3660 KB Output is correct
6 Correct 30 ms 4676 KB Output is correct
7 Correct 34 ms 5324 KB Output is correct
8 Correct 17 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2560 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2556 KB Output is correct
27 Correct 48 ms 3400 KB Output is correct
28 Correct 44 ms 5112 KB Output is correct
29 Correct 46 ms 5200 KB Output is correct
30 Correct 43 ms 5448 KB Output is correct
31 Correct 41 ms 4280 KB Output is correct
32 Correct 11 ms 3040 KB Output is correct
33 Correct 11 ms 3320 KB Output is correct
34 Correct 11 ms 3152 KB Output is correct
35 Correct 9 ms 3152 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 10 ms 3020 KB Output is correct
38 Correct 11 ms 3152 KB Output is correct
39 Correct 21 ms 3664 KB Output is correct
40 Correct 21 ms 3920 KB Output is correct
41 Correct 50 ms 5320 KB Output is correct
42 Correct 34 ms 4732 KB Output is correct
43 Correct 18 ms 3660 KB Output is correct
44 Correct 30 ms 4676 KB Output is correct
45 Correct 34 ms 5324 KB Output is correct
46 Correct 17 ms 2896 KB Output is correct
47 Correct 23 ms 4020 KB Output is correct
48 Correct 22 ms 3920 KB Output is correct
49 Correct 44 ms 5456 KB Output is correct
50 Correct 34 ms 4680 KB Output is correct
51 Correct 27 ms 4088 KB Output is correct
52 Correct 35 ms 4680 KB Output is correct
53 Correct 31 ms 4680 KB Output is correct
54 Correct 36 ms 5456 KB Output is correct
55 Correct 42 ms 5412 KB Output is correct