# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395839 | 2021-04-29T03:26:13 Z | Qw3rTy | Global Warming (CEOI18_glo) | C++11 | 60 ms | 5132 KB |
#include <bits/stdc++.h> #define pb push_back using namespace std; const int maxN = 2e5+5; int a[maxN]; int f[maxN]; //length of LIS that ends on a[i] int g[maxN]; //Length of longest decreasing subsequence that ends at a[i] int N,d; bool cmp(const int &a, const int &b){return a > b;} void testIO(){ freopen("../test.in","r",stdin); return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //testIO(); cin >> N >> d; for(int i = 1; i <= N; ++i)cin >> a[i]; a[0] = -1; //Calculate f f[0] = 0; vector<int> dp; for(int i = 1; i <= N; ++i){ int pos = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin(); if(pos == dp.size()) dp.pb(a[i]); else dp[pos] = a[i]; f[i] = pos + 1; } //Calculate g g[N+1] = 0; dp.clear(); for(int i = N; i >= 1; --i){ int pos1 = lower_bound(dp.begin(),dp.end(),a[i] - d, cmp) - dp.begin(); int pos2 = lower_bound(dp.begin(),dp.end(),a[i],cmp) - dp.begin(); if(pos2 == dp.size()) dp.pb(a[i]); else dp[pos2] = a[i]; g[i] = pos1+1; } // for(int i = N; i >= 1; --i){ // int pos = lower_bound(dp.begin(),dp.end(),a[i],cmp) - dp.begin(); // if(pos == dp.size()) // dp.pb(a[i]); // else dp[pos] = a[i]; // g[i] = pos + 1; // } //Calculate answer int res = f[N]; //Decrease all elements by d is the same as not changing at all = f[N] (basic LIS) for(int i = 1; i <= N; ++i){ res = max(res, f[i] + g[i] - 1); } cout << res << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 328 KB | Output is correct |
14 | Correct | 1 ms | 328 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 328 KB | Output is correct |
14 | Correct | 1 ms | 328 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 2644 KB | Output is correct |
2 | Correct | 59 ms | 2556 KB | Output is correct |
3 | Correct | 60 ms | 2548 KB | Output is correct |
4 | Correct | 60 ms | 2616 KB | Output is correct |
5 | Correct | 45 ms | 3160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 844 KB | Output is correct |
2 | Correct | 14 ms | 892 KB | Output is correct |
3 | Correct | 14 ms | 844 KB | Output is correct |
4 | Correct | 13 ms | 1100 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 10 ms | 1100 KB | Output is correct |
7 | Correct | 13 ms | 844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 1376 KB | Output is correct |
2 | Correct | 27 ms | 1604 KB | Output is correct |
3 | Correct | 57 ms | 4556 KB | Output is correct |
4 | Correct | 46 ms | 4268 KB | Output is correct |
5 | Correct | 21 ms | 2340 KB | Output is correct |
6 | Correct | 34 ms | 4164 KB | Output is correct |
7 | Correct | 44 ms | 4804 KB | Output is correct |
8 | Correct | 25 ms | 2392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 328 KB | Output is correct |
14 | Correct | 1 ms | 328 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 58 ms | 2644 KB | Output is correct |
28 | Correct | 59 ms | 2556 KB | Output is correct |
29 | Correct | 60 ms | 2548 KB | Output is correct |
30 | Correct | 60 ms | 2616 KB | Output is correct |
31 | Correct | 45 ms | 3160 KB | Output is correct |
32 | Correct | 14 ms | 844 KB | Output is correct |
33 | Correct | 14 ms | 892 KB | Output is correct |
34 | Correct | 14 ms | 844 KB | Output is correct |
35 | Correct | 13 ms | 1100 KB | Output is correct |
36 | Correct | 1 ms | 204 KB | Output is correct |
37 | Correct | 10 ms | 1100 KB | Output is correct |
38 | Correct | 13 ms | 844 KB | Output is correct |
39 | Correct | 27 ms | 1376 KB | Output is correct |
40 | Correct | 27 ms | 1604 KB | Output is correct |
41 | Correct | 57 ms | 4556 KB | Output is correct |
42 | Correct | 46 ms | 4268 KB | Output is correct |
43 | Correct | 21 ms | 2340 KB | Output is correct |
44 | Correct | 34 ms | 4164 KB | Output is correct |
45 | Correct | 44 ms | 4804 KB | Output is correct |
46 | Correct | 25 ms | 2392 KB | Output is correct |
47 | Correct | 29 ms | 2372 KB | Output is correct |
48 | Correct | 29 ms | 2396 KB | Output is correct |
49 | Correct | 60 ms | 4564 KB | Output is correct |
50 | Correct | 45 ms | 4388 KB | Output is correct |
51 | Correct | 40 ms | 3368 KB | Output is correct |
52 | Correct | 45 ms | 4424 KB | Output is correct |
53 | Correct | 38 ms | 4364 KB | Output is correct |
54 | Correct | 51 ms | 5132 KB | Output is correct |
55 | Correct | 51 ms | 4548 KB | Output is correct |