답안 #873817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873817 2023-11-15T20:27:51 Z MisterReaper Global Warming (CEOI18_glo) C++17
100 / 100
48 ms 3604 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int INF = 2E9;

ostream& operator<< (ostream& out, vector <int> dp) {
    out << "{";
    for(int i = 0; i < int(dp.size()); i++) {
        out << (abs(dp[i]) == INF ? -23 : dp[i]);
        if(i +1 != int(dp.size()))
            out << ", ";
    }

    return out << "}";
}

#define ONLINE_JUDGE
void solve() {
    int n, x;
    cin >> n >> x;

    vector <int> t(n +1);
    for(int i = 1; i <= n; i++)
        cin >> t[i];

    vector <int> dp(n +1, INF), left(n +1);
    for(int i = 1; i <= n; i++) {
        int idx = lower_bound(dp.begin(), dp.end(), t[i]) - dp.begin();
        dp[idx] = t[i];
        left[i] = idx +1;
    }

    dp = vector <int> (n +1, INF);

    int ans = 0;
    for(int i = n; i >= 1; i--) {
        int idx = lower_bound(dp.begin(), dp.end(), -(t[i] - x)) - dp.begin();
        //cerr << i << " :: " << left[i] << " " << idx << " -> " << dp << "\n";
        ans = max(ans, left[i] + idx);
        idx = lower_bound(dp.begin(), dp.end(), -t[i]) - dp.begin();
        dp[idx] = -t[i];
    }

    cout << ans;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3412 KB Output is correct
2 Correct 47 ms 3408 KB Output is correct
3 Correct 47 ms 3416 KB Output is correct
4 Correct 48 ms 3420 KB Output is correct
5 Correct 34 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1116 KB Output is correct
2 Correct 11 ms 1116 KB Output is correct
3 Correct 13 ms 1176 KB Output is correct
4 Correct 8 ms 1112 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 9 ms 1116 KB Output is correct
7 Correct 9 ms 1168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1884 KB Output is correct
2 Correct 20 ms 1884 KB Output is correct
3 Correct 44 ms 3420 KB Output is correct
4 Correct 33 ms 3420 KB Output is correct
5 Correct 16 ms 1884 KB Output is correct
6 Correct 26 ms 3264 KB Output is correct
7 Correct 31 ms 3216 KB Output is correct
8 Correct 17 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 48 ms 3412 KB Output is correct
28 Correct 47 ms 3408 KB Output is correct
29 Correct 47 ms 3416 KB Output is correct
30 Correct 48 ms 3420 KB Output is correct
31 Correct 34 ms 3420 KB Output is correct
32 Correct 11 ms 1116 KB Output is correct
33 Correct 11 ms 1116 KB Output is correct
34 Correct 13 ms 1176 KB Output is correct
35 Correct 8 ms 1112 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 9 ms 1116 KB Output is correct
38 Correct 9 ms 1168 KB Output is correct
39 Correct 20 ms 1884 KB Output is correct
40 Correct 20 ms 1884 KB Output is correct
41 Correct 44 ms 3420 KB Output is correct
42 Correct 33 ms 3420 KB Output is correct
43 Correct 16 ms 1884 KB Output is correct
44 Correct 26 ms 3264 KB Output is correct
45 Correct 31 ms 3216 KB Output is correct
46 Correct 17 ms 1880 KB Output is correct
47 Correct 23 ms 1880 KB Output is correct
48 Correct 23 ms 1884 KB Output is correct
49 Correct 47 ms 3412 KB Output is correct
50 Correct 33 ms 3604 KB Output is correct
51 Correct 28 ms 2648 KB Output is correct
52 Correct 41 ms 3408 KB Output is correct
53 Correct 29 ms 3420 KB Output is correct
54 Correct 32 ms 3416 KB Output is correct
55 Correct 38 ms 3420 KB Output is correct