답안 #763641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763641 2023-06-22T14:39:33 Z AutomatiC__ Global Warming (CEOI18_glo) C++17
100 / 100
110 ms 5828 KB
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 200005;
int a[maxn];
int n, x;
int f[maxn], g[maxn]; // f prefix, g suffix
int main() {
    cin >> n >> x;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<int> dp1;
    for (int i = 1; i <= n; i++) {
        if (dp1.empty() || a[i] > dp1.back()) {
            dp1.push_back(a[i]);
            f[i] = dp1.size();
        } else {
            int pos = lower_bound(dp1.begin(), dp1.end(), a[i]) - dp1.begin();
            dp1[pos] = a[i];
            f[i] = pos + 1;
        }
    }
    vector<int> dp2(n + 2, inf);
    for (int i = n; i >= 1; i--) {
        int pos1 = lower_bound(dp2.begin(), dp2.end(), -(a[i] - x)) - dp2.begin();
        int pos2 = lower_bound(dp2.begin(), dp2.end(), -a[i]) - dp2.begin();
        dp2[pos2] = -a[i];
        g[i] = pos1;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, f[i] + g[i]);
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 3380 KB Output is correct
2 Correct 86 ms 5352 KB Output is correct
3 Correct 85 ms 5340 KB Output is correct
4 Correct 87 ms 5332 KB Output is correct
5 Correct 56 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1108 KB Output is correct
2 Correct 21 ms 1512 KB Output is correct
3 Correct 21 ms 1580 KB Output is correct
4 Correct 15 ms 1512 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 15 ms 1620 KB Output is correct
7 Correct 19 ms 1576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 1872 KB Output is correct
2 Correct 40 ms 2788 KB Output is correct
3 Correct 79 ms 5292 KB Output is correct
4 Correct 56 ms 5020 KB Output is correct
5 Correct 31 ms 2672 KB Output is correct
6 Correct 51 ms 4856 KB Output is correct
7 Correct 65 ms 5620 KB Output is correct
8 Correct 36 ms 2844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 110 ms 3380 KB Output is correct
28 Correct 86 ms 5352 KB Output is correct
29 Correct 85 ms 5340 KB Output is correct
30 Correct 87 ms 5332 KB Output is correct
31 Correct 56 ms 5076 KB Output is correct
32 Correct 21 ms 1108 KB Output is correct
33 Correct 21 ms 1512 KB Output is correct
34 Correct 21 ms 1580 KB Output is correct
35 Correct 15 ms 1512 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 15 ms 1620 KB Output is correct
38 Correct 19 ms 1576 KB Output is correct
39 Correct 40 ms 1872 KB Output is correct
40 Correct 40 ms 2788 KB Output is correct
41 Correct 79 ms 5292 KB Output is correct
42 Correct 56 ms 5020 KB Output is correct
43 Correct 31 ms 2672 KB Output is correct
44 Correct 51 ms 4856 KB Output is correct
45 Correct 65 ms 5620 KB Output is correct
46 Correct 36 ms 2844 KB Output is correct
47 Correct 41 ms 2840 KB Output is correct
48 Correct 42 ms 2804 KB Output is correct
49 Correct 85 ms 5248 KB Output is correct
50 Correct 59 ms 5096 KB Output is correct
51 Correct 47 ms 3944 KB Output is correct
52 Correct 57 ms 5144 KB Output is correct
53 Correct 54 ms 5212 KB Output is correct
54 Correct 67 ms 5828 KB Output is correct
55 Correct 76 ms 5276 KB Output is correct