답안 #1067684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067684 2024-08-21T00:42:33 Z CodeLakVN Global Warming (CEOI18_glo) C++17
45 / 100
43 ms 5516 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define name "LIS"
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, b, a) for (int i = (b); i >= (a); i--)

template <class U, class V>
    bool maximize(U &x, V y) {
        if (x < y) { x = y; return true; }
        return false;
    }

template <class U, class V>
    bool minimize(U &x, V y) {
        if (x > y) { x = y; return true; }
        return false;
    }

const int INF = 1e9;
const int N = 3e5 + 5;

int a[N];

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);
    if (fopen(name".inp", "r")) {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }

    int n, d;
    cin >> n >> d;
    FOR(i, 1, n) cin >> a[i];

    vector<int> f(n + 1, 0); f[0] = INF;
    vector<int> suff(n + 1, 0);

    int ans = 0;
    FOD(i, n, 1) {
        int idx = lower_bound(f.begin(), f.end(), a[i], greater<int>()) - f.begin();
        suff[i] = idx;
        f[idx] = a[i];
        maximize(ans, idx);
    }

    f = vector<int>(n + 1, INF); f[0] = 0;
    FOR(i, 1, n - 1) {
        int idx = lower_bound(f.begin(), f.end(), a[i]) - f.begin();
        f[idx] = a[i];
        idx = lower_bound(f.begin(), f.end(), a[i + 1] + d) - f.begin();
        maximize(ans, idx + suff[i + 1] - 1);
    }

    cout << ans;

    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 600 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 5460 KB Output is correct
2 Correct 41 ms 5516 KB Output is correct
3 Correct 43 ms 5464 KB Output is correct
4 Correct 40 ms 5456 KB Output is correct
5 Correct 28 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1628 KB Output is correct
2 Correct 9 ms 1496 KB Output is correct
3 Correct 10 ms 1628 KB Output is correct
4 Correct 7 ms 1372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 8 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 600 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 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 600 KB Output isn't correct
20 Halted 0 ms 0 KB -