Submission #246340

# Submission time Handle Problem Language Result Execution time Memory
246340 2020-07-08T17:53:18 Z Sorting Global Warming (CEOI18_glo) C++14
55 / 100
2000 ms 3052 KB
#include <bits/stdc++.h>

using namespace std;

const int k_N = 2e5 + 3;
const int k_Inf = 1e9 + 3;

int n, x;
int t[k_N];

int ans[k_N];

int get_lis(){
    vector<int> dp;
    dp.push_back({-k_Inf});

    for(int i = 0; i < n; ++i){
        auto it = lower_bound(dp.begin(), dp.end(), t[i]);
        if(it == dp.end())
            dp.push_back(t[i]);
        else
            dp[it - dp.begin()] = t[i];

        ans[i] += dp.size() - 1;
    }
    return dp.size() - 1;
}

void get_lds(){
    vector<int> dp;
    dp.push_back({k_Inf});

    for(int i = n - 1; i >= 0; --i){
        int l = 0, r = dp.size();
        while(l != r){
            int mid = (l + r) >> 1;
            if(t[i] >= dp[mid])
                r = mid;
            else
                l = mid + 1;
        }
        if(l == dp.size())
            dp.push_back(t[i]);
        else
            dp[l] = t[i];

        //cout << dp.size() << "\n";
        ans[i - 1] += dp.size() - 1;
    }
}

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

    cin >> n >> x;
    for(int i = 0; i < n; ++i)
        cin >> t[i];

    if(x == k_Inf - 3){
        int answer = 0;
        get_lds();
        get_lis();

        for(int i = 0; i < n; ++i)
            answer = max(ans[i], answer);

        cout << answer << "\n";
    }
    else{
        int answer = 0;
        for(int i = 0; i < n; ++i){
            t[i] -= x;
            answer = max(get_lis(), answer);
            if(x == 0)
                break;
        }

        cout << answer << "\n";
    }
}

Compilation message

glo.cpp: In function 'void get_lds()':
glo.cpp:42:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(l == dp.size())
            ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 26 ms 384 KB Output is correct
20 Correct 24 ms 384 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 22 ms 384 KB Output is correct
24 Correct 22 ms 384 KB Output is correct
25 Correct 19 ms 384 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2296 KB Output is correct
2 Correct 45 ms 2168 KB Output is correct
3 Correct 44 ms 2168 KB Output is correct
4 Correct 46 ms 2296 KB Output is correct
5 Correct 33 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1528 KB Output is correct
2 Correct 30 ms 1400 KB Output is correct
3 Correct 56 ms 2168 KB Output is correct
4 Correct 39 ms 3052 KB Output is correct
5 Correct 21 ms 1852 KB Output is correct
6 Correct 33 ms 2944 KB Output is correct
7 Correct 38 ms 2944 KB Output is correct
8 Correct 27 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 26 ms 384 KB Output is correct
20 Correct 24 ms 384 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 22 ms 384 KB Output is correct
24 Correct 22 ms 384 KB Output is correct
25 Correct 19 ms 384 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
27 Correct 44 ms 2296 KB Output is correct
28 Correct 45 ms 2168 KB Output is correct
29 Correct 44 ms 2168 KB Output is correct
30 Correct 46 ms 2296 KB Output is correct
31 Correct 33 ms 2804 KB Output is correct
32 Execution timed out 2070 ms 1024 KB Time limit exceeded
33 Halted 0 ms 0 KB -