답안 #1095607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095607 2024-10-02T16:58:04 Z TrinhKhanhDung Global Warming (CEOI18_glo) C++14
100 / 100
44 ms 5492 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18 + 10
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 2e5 + 10;

int N, X;
int a[MAX], L[MAX], R[MAX];

void solve(){
    cin >> N >> X;
    for(int i = 1; i <= N; i++) cin >> a[i];

    vector<int> len(N + 3, INF);
    for(int i = 1; i <= N; i++){
        int p = lower_bound(ALL(len), a[i]) - len.begin();
        L[i] = p + 1;
        len[p] = a[i];
    }

    len = vector<int>(N + 3, INF);
    for(int i = N; i >= 1; i--){
        int p = lower_bound(ALL(len), - a[i] + X) - len.begin();
        R[i] = p + 1;
        p = lower_bound(ALL(len), - a[i]) - len.begin();
        len[p] = - a[i];
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) maximize(ans, L[i] + R[i] - 1);

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("bdbang.inp","r",stdin);
//     freopen("bdbang.out","w",stdout);

    int t = 1;
//    cin >> t;
    while(t--)
        solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 5492 KB Output is correct
2 Correct 44 ms 5456 KB Output is correct
3 Correct 41 ms 5464 KB Output is correct
4 Correct 42 ms 5348 KB Output is correct
5 Correct 29 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1684 KB Output is correct
2 Correct 12 ms 1560 KB Output is correct
3 Correct 10 ms 1656 KB Output is correct
4 Correct 7 ms 1508 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1432 KB Output is correct
7 Correct 8 ms 1688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2892 KB Output is correct
2 Correct 19 ms 2904 KB Output is correct
3 Correct 36 ms 5460 KB Output is correct
4 Correct 29 ms 4700 KB Output is correct
5 Correct 15 ms 2516 KB Output is correct
6 Correct 26 ms 4460 KB Output is correct
7 Correct 27 ms 5312 KB Output is correct
8 Correct 16 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 40 ms 5492 KB Output is correct
28 Correct 44 ms 5456 KB Output is correct
29 Correct 41 ms 5464 KB Output is correct
30 Correct 42 ms 5348 KB Output is correct
31 Correct 29 ms 4700 KB Output is correct
32 Correct 10 ms 1684 KB Output is correct
33 Correct 12 ms 1560 KB Output is correct
34 Correct 10 ms 1656 KB Output is correct
35 Correct 7 ms 1508 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 7 ms 1432 KB Output is correct
38 Correct 8 ms 1688 KB Output is correct
39 Correct 18 ms 2892 KB Output is correct
40 Correct 19 ms 2904 KB Output is correct
41 Correct 36 ms 5460 KB Output is correct
42 Correct 29 ms 4700 KB Output is correct
43 Correct 15 ms 2516 KB Output is correct
44 Correct 26 ms 4460 KB Output is correct
45 Correct 27 ms 5312 KB Output is correct
46 Correct 16 ms 3028 KB Output is correct
47 Correct 19 ms 2908 KB Output is correct
48 Correct 20 ms 2896 KB Output is correct
49 Correct 43 ms 5452 KB Output is correct
50 Correct 34 ms 4688 KB Output is correct
51 Correct 26 ms 3672 KB Output is correct
52 Correct 30 ms 4828 KB Output is correct
53 Correct 26 ms 4700 KB Output is correct
54 Correct 31 ms 5324 KB Output is correct
55 Correct 34 ms 5460 KB Output is correct