Submission #259949

# Submission time Handle Problem Language Result Execution time Memory
259949 2020-08-08T20:48:35 Z pedroslrey Global Warming (CEOI18_glo) C++17
100 / 100
85 ms 3596 KB
#include <bits/stdc++.h>

using namespace std;
 
const int MAXN = 2e5 + 10;
const int INF = 2e9;

int xs[MAXN];
int dp_lis[MAXN];
int dp_lds[MAXN];
int pos[MAXN];
 
int main() {
	int n, x;
	scanf("%d %d", &n, &x);

	for (int i = 1; i <= n; ++i)
		scanf("%d", &xs[i]);
	
	for (int i = 1; i <= n; ++i)
		dp_lis[i] = INF;

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int p = lower_bound(dp_lis, dp_lis + n + 1, xs[i]) - dp_lis;
		
		dp_lis[p] = xs[i];
		ans = max(ans, p);
		pos[i] = p;
	}

	for(int i = 1; i <= n; ++i)
		dp_lds[i] = INF;

	dp_lds[0] = -INF;
	for (int i = n; i >= 1; --i) {
		int idx = lower_bound(dp_lds, dp_lds + n + 1, -xs[i]) - dp_lds - 1;
		int p = lower_bound(dp_lds, dp_lds + n + 1, -xs[i] - x) - dp_lds;
		
		dp_lds[p] = -xs[i] - x;
		ans = max(ans, pos[i] + idx);
	}
	printf("%d\n", ans);
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &xs[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 3576 KB Output is correct
2 Correct 85 ms 3468 KB Output is correct
3 Correct 81 ms 3448 KB Output is correct
4 Correct 80 ms 3452 KB Output is correct
5 Correct 65 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1152 KB Output is correct
2 Correct 20 ms 1152 KB Output is correct
3 Correct 23 ms 1152 KB Output is correct
4 Correct 21 ms 1152 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 14 ms 1152 KB Output is correct
7 Correct 15 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1920 KB Output is correct
2 Correct 44 ms 1920 KB Output is correct
3 Correct 72 ms 3596 KB Output is correct
4 Correct 76 ms 3436 KB Output is correct
5 Correct 36 ms 1920 KB Output is correct
6 Correct 49 ms 3320 KB Output is correct
7 Correct 53 ms 3280 KB Output is correct
8 Correct 30 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 81 ms 3576 KB Output is correct
28 Correct 85 ms 3468 KB Output is correct
29 Correct 81 ms 3448 KB Output is correct
30 Correct 80 ms 3452 KB Output is correct
31 Correct 65 ms 3448 KB Output is correct
32 Correct 23 ms 1152 KB Output is correct
33 Correct 20 ms 1152 KB Output is correct
34 Correct 23 ms 1152 KB Output is correct
35 Correct 21 ms 1152 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 14 ms 1152 KB Output is correct
38 Correct 15 ms 1152 KB Output is correct
39 Correct 35 ms 1920 KB Output is correct
40 Correct 44 ms 1920 KB Output is correct
41 Correct 72 ms 3596 KB Output is correct
42 Correct 76 ms 3436 KB Output is correct
43 Correct 36 ms 1920 KB Output is correct
44 Correct 49 ms 3320 KB Output is correct
45 Correct 53 ms 3280 KB Output is correct
46 Correct 30 ms 1920 KB Output is correct
47 Correct 37 ms 1948 KB Output is correct
48 Correct 38 ms 1912 KB Output is correct
49 Correct 76 ms 3492 KB Output is correct
50 Correct 58 ms 3448 KB Output is correct
51 Correct 44 ms 2680 KB Output is correct
52 Correct 70 ms 3448 KB Output is correct
53 Correct 60 ms 3452 KB Output is correct
54 Correct 59 ms 3448 KB Output is correct
55 Correct 66 ms 3452 KB Output is correct