답안 #166132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166132 2019-11-30T21:56:01 Z GustavK Global Warming (CEOI18_glo) C++14
75 / 100
1678 ms 10204 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 1000000007;
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

int LIS(vl a){
    vl b(200010, linf);
    int r = 0;
    for(int i = 0; i < sz(a); i++){
        auto p = lower_bound(all(b), a[i]);
        if(*p == linf) r++;
        *p = a[i];
    }
    return r;
}

vl A;
int dp[100000];
int LIS2(int pos){
    if(dp[pos] != -1) return dp[pos];
    int r = 0;
    for(int i = pos+1; i < sz(A); i++){
        if(A[i] > A[pos])
            r = max(r, LIS2(i));
    }
    return dp[pos] = r + 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, x;
    cin >> n >> x;
    vl a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vl b(200010, linf);
    stack<pair<ll,ll>> undo;
    for(int i = n-1; i >= 0; i--){
        int p = lower_bound(all(b), -a[i]-x) - b.begin();
        undo.emplace(p, b[p]);
        b[p] = -a[i]-x;
    }

    vl c(200010, linf);
    int len = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        b[undo.top().first] = undo.top().second;
        undo.pop();

        int p = lower_bound(all(c), a[i]) - c.begin();
        if(c[p] == linf) len++;
        if(p+1 == len){
            ans = max(ans, len + (int)(lower_bound(all(b), -a[i]) - b.begin()));
        }
        c[p] = a[i];
    }

    if(n <= 1000){
        ans = 0;
        for(int i = n-1; i >= 0; i--){
            a[i] += x;
            A = a;
            memset(dp, -1, sizeof(dp));
            for(int j = 0; j < n; j++)
                ans = max(ans, LIS2(j));
        }
    }

    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3832 KB Output is correct
9 Correct 5 ms 3832 KB Output is correct
10 Correct 5 ms 3832 KB Output is correct
11 Correct 5 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3832 KB Output is correct
9 Correct 5 ms 3832 KB Output is correct
10 Correct 5 ms 3832 KB Output is correct
11 Correct 5 ms 3832 KB Output is correct
12 Correct 6 ms 3832 KB Output is correct
13 Correct 6 ms 3832 KB Output is correct
14 Correct 6 ms 3804 KB Output is correct
15 Correct 6 ms 3832 KB Output is correct
16 Correct 6 ms 3832 KB Output is correct
17 Correct 5 ms 3836 KB Output is correct
18 Correct 5 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3832 KB Output is correct
9 Correct 5 ms 3832 KB Output is correct
10 Correct 5 ms 3832 KB Output is correct
11 Correct 5 ms 3832 KB Output is correct
12 Correct 6 ms 3832 KB Output is correct
13 Correct 6 ms 3832 KB Output is correct
14 Correct 6 ms 3804 KB Output is correct
15 Correct 6 ms 3832 KB Output is correct
16 Correct 6 ms 3832 KB Output is correct
17 Correct 5 ms 3836 KB Output is correct
18 Correct 5 ms 3832 KB Output is correct
19 Correct 1657 ms 3964 KB Output is correct
20 Correct 1678 ms 3960 KB Output is correct
21 Correct 1619 ms 3836 KB Output is correct
22 Correct 1633 ms 3960 KB Output is correct
23 Correct 1065 ms 4088 KB Output is correct
24 Correct 1103 ms 3960 KB Output is correct
25 Correct 782 ms 4088 KB Output is correct
26 Correct 1077 ms 3972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 8312 KB Output is correct
2 Correct 68 ms 8312 KB Output is correct
3 Correct 68 ms 8312 KB Output is correct
4 Correct 68 ms 8284 KB Output is correct
5 Correct 59 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4728 KB Output is correct
2 Correct 20 ms 4728 KB Output is correct
3 Correct 19 ms 4728 KB Output is correct
4 Correct 18 ms 4728 KB Output is correct
5 Correct 5 ms 3832 KB Output is correct
6 Correct 24 ms 4728 KB Output is correct
7 Correct 18 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 5880 KB Output is correct
2 Correct 36 ms 5952 KB Output is correct
3 Correct 67 ms 8368 KB Output is correct
4 Correct 59 ms 8312 KB Output is correct
5 Correct 36 ms 5880 KB Output is correct
6 Correct 53 ms 8056 KB Output is correct
7 Correct 62 ms 8056 KB Output is correct
8 Correct 32 ms 5960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
3 Correct 5 ms 3832 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3832 KB Output is correct
6 Correct 5 ms 3832 KB Output is correct
7 Correct 5 ms 3832 KB Output is correct
8 Correct 5 ms 3832 KB Output is correct
9 Correct 5 ms 3832 KB Output is correct
10 Correct 5 ms 3832 KB Output is correct
11 Correct 5 ms 3832 KB Output is correct
12 Correct 6 ms 3832 KB Output is correct
13 Correct 6 ms 3832 KB Output is correct
14 Correct 6 ms 3804 KB Output is correct
15 Correct 6 ms 3832 KB Output is correct
16 Correct 6 ms 3832 KB Output is correct
17 Correct 5 ms 3836 KB Output is correct
18 Correct 5 ms 3832 KB Output is correct
19 Correct 1657 ms 3964 KB Output is correct
20 Correct 1678 ms 3960 KB Output is correct
21 Correct 1619 ms 3836 KB Output is correct
22 Correct 1633 ms 3960 KB Output is correct
23 Correct 1065 ms 4088 KB Output is correct
24 Correct 1103 ms 3960 KB Output is correct
25 Correct 782 ms 4088 KB Output is correct
26 Correct 1077 ms 3972 KB Output is correct
27 Correct 69 ms 8312 KB Output is correct
28 Correct 68 ms 8312 KB Output is correct
29 Correct 68 ms 8312 KB Output is correct
30 Correct 68 ms 8284 KB Output is correct
31 Correct 59 ms 8284 KB Output is correct
32 Correct 20 ms 4728 KB Output is correct
33 Correct 20 ms 4728 KB Output is correct
34 Correct 19 ms 4728 KB Output is correct
35 Correct 18 ms 4728 KB Output is correct
36 Correct 5 ms 3832 KB Output is correct
37 Correct 24 ms 4728 KB Output is correct
38 Correct 18 ms 4728 KB Output is correct
39 Correct 35 ms 5880 KB Output is correct
40 Correct 36 ms 5952 KB Output is correct
41 Correct 67 ms 8368 KB Output is correct
42 Correct 59 ms 8312 KB Output is correct
43 Correct 36 ms 5880 KB Output is correct
44 Correct 53 ms 8056 KB Output is correct
45 Correct 62 ms 8056 KB Output is correct
46 Correct 32 ms 5960 KB Output is correct
47 Correct 65 ms 6904 KB Output is correct
48 Correct 36 ms 6904 KB Output is correct
49 Incorrect 67 ms 10204 KB Output isn't correct
50 Halted 0 ms 0 KB -