답안 #469446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469446 2021-09-01T02:15:54 Z dooompy Global Warming (CEOI18_glo) C++17
100 / 100
58 ms 4300 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int dp[200050];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, x; cin >> n >> x;
    vector<int> v(n);
    for (auto &a : v) cin >> a;

    int ans = 0;

    vector<int> lis;
    for (int i = 0; i < n; i++) {
        int pos = lower_bound(lis.begin(), lis.end(), v[i]) - lis.begin();
        if (pos == lis.size()) {
            lis.push_back(v[i]);
        } else {
            lis[pos] = v[i];
        }
        dp[i] = pos + 1;
        ans = max(ans, dp[i]);
    }

    lis.clear();
    for (int i = n-1; i >= 0; i--) {
        int anspos = lower_bound(lis.begin(), lis.end(), -v[i] + x) - lis.begin();
        ans = max(ans, dp[i] + anspos);
        int pos = lower_bound(lis.begin(), lis.end(), -v[i]) - lis.begin();
        if (pos == lis.size()) {
            lis.push_back(-v[i]);
        } else {
            lis[pos] = -v[i];
        }
    }


    cout << ans;

}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if (pos == lis.size()) {
      |             ~~~~^~~~~~~~~~~~~
glo.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (pos == lis.size()) {
      |             ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 252 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 252 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 252 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 1772 KB Output is correct
2 Correct 56 ms 3784 KB Output is correct
3 Correct 58 ms 3752 KB Output is correct
4 Correct 56 ms 3792 KB Output is correct
5 Correct 34 ms 3528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 716 KB Output is correct
2 Correct 13 ms 716 KB Output is correct
3 Correct 13 ms 660 KB Output is correct
4 Correct 9 ms 844 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 11 ms 844 KB Output is correct
7 Correct 11 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1088 KB Output is correct
2 Correct 25 ms 1092 KB Output is correct
3 Correct 51 ms 1828 KB Output is correct
4 Correct 34 ms 3520 KB Output is correct
5 Correct 16 ms 2020 KB Output is correct
6 Correct 31 ms 3496 KB Output is correct
7 Correct 36 ms 4136 KB Output is correct
8 Correct 22 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 252 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 54 ms 1772 KB Output is correct
28 Correct 56 ms 3784 KB Output is correct
29 Correct 58 ms 3752 KB Output is correct
30 Correct 56 ms 3792 KB Output is correct
31 Correct 34 ms 3528 KB Output is correct
32 Correct 13 ms 716 KB Output is correct
33 Correct 13 ms 716 KB Output is correct
34 Correct 13 ms 660 KB Output is correct
35 Correct 9 ms 844 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 11 ms 844 KB Output is correct
38 Correct 11 ms 716 KB Output is correct
39 Correct 28 ms 1088 KB Output is correct
40 Correct 25 ms 1092 KB Output is correct
41 Correct 51 ms 1828 KB Output is correct
42 Correct 34 ms 3520 KB Output is correct
43 Correct 16 ms 2020 KB Output is correct
44 Correct 31 ms 3496 KB Output is correct
45 Correct 36 ms 4136 KB Output is correct
46 Correct 22 ms 2028 KB Output is correct
47 Correct 28 ms 1996 KB Output is correct
48 Correct 28 ms 1988 KB Output is correct
49 Correct 55 ms 3780 KB Output is correct
50 Correct 34 ms 3532 KB Output is correct
51 Correct 29 ms 2768 KB Output is correct
52 Correct 34 ms 3652 KB Output is correct
53 Correct 29 ms 3660 KB Output is correct
54 Correct 36 ms 4300 KB Output is correct
55 Correct 46 ms 3708 KB Output is correct