Submission #477277

# Submission time Handle Problem Language Result Execution time Memory
477277 2021-10-01T14:38:32 Z Shogun3103 Global Warming (CEOI18_glo) C++17
100 / 100
68 ms 10056 KB
#include <bits/stdc++.h>
 
using namespace std;

#define ll long long
#define ld long double
#define FOR(i,a,b) for(__typeof(b) i=a; i<=b; i++)
#define FOD(i,a,b) for(__typeof(b) i=b; i>=a; i--)
#define EACH(u, v) for(auto& u : v)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,ii>
#define f first
#define s second
#define ed "\n"
#define sp " "
#define vi vector<int>
#define vii vector<ii>
#define vl vector<ll>
#define NO cout << "NO" << ed;
#define YES cout << "YES" << ed;
#define no cout << "no" << ed;
#define yes cout << "yes" << ed;

void setIO(string fileName = ""){
    if(fileName.length()){
        freopen((fileName+".in").c_str(), "r", stdin);
        freopen((fileName+".out").c_str(), "w", stdout);
    }
}

int lnds(vl a)
{
    vi calc;
    for(int q : a) {
        int pos = upper_bound(all(calc), q) - calc.begin();
        if(pos == sz(calc)) calc.pb(q);
        else calc[pos] = q;
    }
    return sz(calc);
}

const int oo1 = 1e9 + 7;
const int oo2 = 1e9 + 9;
const int d4x[] = {0, 0, 1, -1};
const int d4y[] = {1, -1, 0, 0};
const int d8x[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int d8y[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int N = 2e5 + 10;
const int M = 5e3 + 10;
vi adj[N];

int n, m;
int a[N], x, pre[N];

void solve()
{
    cin >> n >> x;
    FOR(i, 1, n) cin >> a[i];

    //left
    int ans = 0;
    vi dp(n, oo1);
    FOR(i, 1, n) {
        int j = lower_bound(all(dp), a[i]) - dp.begin();
        dp[j] = a[i];
        pre[i] = j + 1;
        ans = max(ans, pre[i]);
    }   
    //right
    dp = vi(n, oo1);
    FOD(i, 1, n) {
        int j = lower_bound(all(dp), -a[i] + x) - dp.begin();
        ans = max(ans, pre[i] + j);
        int jj = lower_bound(all(dp), -a[i]) - dp.begin();
        dp[jj] = -a[i];
    }   
    cout << ans;  
}          

int main()
{ 
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);        
    setIO("");
    int t; t = 1;
    //int t; cin >> t;
    FOR(i, 1, t) solve();
    return 0;
}

Compilation message

glo.cpp: In function 'void setIO(std::string)':
glo.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((fileName+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen((fileName+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4936 KB Output is correct
5 Correct 3 ms 5020 KB Output is correct
6 Correct 3 ms 5016 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4936 KB Output is correct
5 Correct 3 ms 5020 KB Output is correct
6 Correct 3 ms 5016 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 4944 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 4 ms 4944 KB Output is correct
18 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4936 KB Output is correct
5 Correct 3 ms 5020 KB Output is correct
6 Correct 3 ms 5016 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 4944 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 4 ms 4944 KB Output is correct
18 Correct 3 ms 4944 KB Output is correct
19 Correct 4 ms 4944 KB Output is correct
20 Correct 3 ms 5024 KB Output is correct
21 Correct 4 ms 4944 KB Output is correct
22 Correct 4 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 4944 KB Output is correct
25 Correct 3 ms 5024 KB Output is correct
26 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 9992 KB Output is correct
2 Correct 61 ms 10056 KB Output is correct
3 Correct 68 ms 10032 KB Output is correct
4 Correct 61 ms 9976 KB Output is correct
5 Correct 45 ms 9296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 6224 KB Output is correct
2 Correct 18 ms 6224 KB Output is correct
3 Correct 17 ms 6352 KB Output is correct
4 Correct 14 ms 5984 KB Output is correct
5 Correct 3 ms 5016 KB Output is correct
6 Correct 14 ms 6164 KB Output is correct
7 Correct 14 ms 6296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7532 KB Output is correct
2 Correct 33 ms 7504 KB Output is correct
3 Correct 56 ms 9968 KB Output is correct
4 Correct 48 ms 9252 KB Output is correct
5 Correct 24 ms 7112 KB Output is correct
6 Correct 43 ms 9168 KB Output is correct
7 Correct 44 ms 9800 KB Output is correct
8 Correct 29 ms 7556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4936 KB Output is correct
5 Correct 3 ms 5020 KB Output is correct
6 Correct 3 ms 5016 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 4944 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 4 ms 4944 KB Output is correct
18 Correct 3 ms 4944 KB Output is correct
19 Correct 4 ms 4944 KB Output is correct
20 Correct 3 ms 5024 KB Output is correct
21 Correct 4 ms 4944 KB Output is correct
22 Correct 4 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 4944 KB Output is correct
25 Correct 3 ms 5024 KB Output is correct
26 Correct 3 ms 4944 KB Output is correct
27 Correct 60 ms 9992 KB Output is correct
28 Correct 61 ms 10056 KB Output is correct
29 Correct 68 ms 10032 KB Output is correct
30 Correct 61 ms 9976 KB Output is correct
31 Correct 45 ms 9296 KB Output is correct
32 Correct 18 ms 6224 KB Output is correct
33 Correct 18 ms 6224 KB Output is correct
34 Correct 17 ms 6352 KB Output is correct
35 Correct 14 ms 5984 KB Output is correct
36 Correct 3 ms 5016 KB Output is correct
37 Correct 14 ms 6164 KB Output is correct
38 Correct 14 ms 6296 KB Output is correct
39 Correct 32 ms 7532 KB Output is correct
40 Correct 33 ms 7504 KB Output is correct
41 Correct 56 ms 9968 KB Output is correct
42 Correct 48 ms 9252 KB Output is correct
43 Correct 24 ms 7112 KB Output is correct
44 Correct 43 ms 9168 KB Output is correct
45 Correct 44 ms 9800 KB Output is correct
46 Correct 29 ms 7556 KB Output is correct
47 Correct 32 ms 7496 KB Output is correct
48 Correct 30 ms 7452 KB Output is correct
49 Correct 61 ms 9980 KB Output is correct
50 Correct 44 ms 9296 KB Output is correct
51 Correct 38 ms 8236 KB Output is correct
52 Correct 46 ms 9400 KB Output is correct
53 Correct 42 ms 9364 KB Output is correct
54 Correct 49 ms 10056 KB Output is correct
55 Correct 54 ms 10056 KB Output is correct