Submission #668830

# Submission time Handle Problem Language Result Execution time Memory
668830 2022-12-05T03:58:33 Z asdf1234coding Global Warming (CEOI18_glo) C++14
100 / 100
56 ms 5952 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;

#define problemname "glo"
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define MOD (int)1e9+7
#define ll long long
#define ff first
#define ss second

bool ckmin(int& a, int b) {return a>b?a=b,true:false;}
bool ckmax(int& a, int b) {return a<b?a=b,true:false;}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen (problemname ".in", "r", stdin); freopen(problemname ".out", "w", stdout);
    int n,x;cin>>n>>x;
    vi a(n); for(auto& x: a) cin>>x;
    vi left;
    vi dp;
    int ans = 0;
    for(auto lmao:a) {
        int pos = lower_bound(dp.begin(), dp.end(), lmao) - dp.begin();
        if(pos == dp.size()) {
            dp.pb(lmao);
        } else {
            dp[pos]=lmao;
        }
        left.pb(pos);
        // cout<<lmao << ' '<<pos<<endl;
        ckmax(ans, left[left.size()-1]);
    }
    // for(auto x:dp) cout<<x<<' ';
    // cout<<endl;
    // cout<<ans<<endl;
    // cout<<"---------------"<<endl;
    dp.clear();
    vi right;
    for(int i=n-1; i>=0; i--) {
        a[i]=-a[i];
        int pos = lower_bound(dp.begin(), dp.end(), a[i] + x) - dp.begin();
        int ins = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
        if(ins == dp.size()) {
            dp.pb(a[i]);
        } else {
            dp[ins]=a[i];
        }
        right.pb(dp.size());
        a[i]=-a[i];
        ckmax(ans, left[i]+pos);
        // cout<<ans<<' '<<i<<endl;
    }
    cout<<ans+1<<endl;
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if(pos == dp.size()) {
      |            ~~~~^~~~~~~~~~~~
glo.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if(ins == dp.size()) {
      |            ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3312 KB Output is correct
2 Correct 48 ms 5316 KB Output is correct
3 Correct 49 ms 5320 KB Output is correct
4 Correct 52 ms 5308 KB Output is correct
5 Correct 29 ms 5424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1040 KB Output is correct
2 Correct 14 ms 1492 KB Output is correct
3 Correct 13 ms 1540 KB Output is correct
4 Correct 7 ms 1456 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1484 KB Output is correct
7 Correct 10 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1872 KB Output is correct
2 Correct 21 ms 1800 KB Output is correct
3 Correct 45 ms 3424 KB Output is correct
4 Correct 30 ms 4916 KB Output is correct
5 Correct 20 ms 2636 KB Output is correct
6 Correct 24 ms 4792 KB Output is correct
7 Correct 29 ms 5784 KB Output is correct
8 Correct 20 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 284 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 56 ms 3312 KB Output is correct
28 Correct 48 ms 5316 KB Output is correct
29 Correct 49 ms 5320 KB Output is correct
30 Correct 52 ms 5308 KB Output is correct
31 Correct 29 ms 5424 KB Output is correct
32 Correct 11 ms 1040 KB Output is correct
33 Correct 14 ms 1492 KB Output is correct
34 Correct 13 ms 1540 KB Output is correct
35 Correct 7 ms 1456 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 8 ms 1484 KB Output is correct
38 Correct 10 ms 1492 KB Output is correct
39 Correct 20 ms 1872 KB Output is correct
40 Correct 21 ms 1800 KB Output is correct
41 Correct 45 ms 3424 KB Output is correct
42 Correct 30 ms 4916 KB Output is correct
43 Correct 20 ms 2636 KB Output is correct
44 Correct 24 ms 4792 KB Output is correct
45 Correct 29 ms 5784 KB Output is correct
46 Correct 20 ms 2892 KB Output is correct
47 Correct 24 ms 2816 KB Output is correct
48 Correct 26 ms 2744 KB Output is correct
49 Correct 51 ms 5312 KB Output is correct
50 Correct 31 ms 5384 KB Output is correct
51 Correct 26 ms 4252 KB Output is correct
52 Correct 29 ms 5028 KB Output is correct
53 Correct 27 ms 5052 KB Output is correct
54 Correct 32 ms 5952 KB Output is correct
55 Correct 42 ms 5316 KB Output is correct