답안 #469444

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

using namespace std;

using ll = long long;

int dp[100005];
int odp[100005];

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 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];
        }

        odp[i] = pos + 1;
        ans = max(ans, odp[i]);
    }


    for (int i = 0; i < n-1; i++) {
        if (abs(v[i+1] - v[i]) < x) {
            ans = max(ans, dp[i] + odp[i+1]);
        }
    }

    cout << ans;

}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if (pos == lis.size()) {
      |             ~~~~^~~~~~~~~~~~~
glo.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (pos == lis.size()) {
      |             ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 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 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 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 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 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 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Incorrect 1 ms 332 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 2768 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 892 KB Output is correct
2 Correct 13 ms 1280 KB Output is correct
3 Correct 13 ms 1396 KB Output is correct
4 Incorrect 9 ms 1356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1484 KB Output is correct
2 Incorrect 28 ms 1488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 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 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Incorrect 1 ms 332 KB Output isn't correct
21 Halted 0 ms 0 KB -