답안 #927280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927280 2024-02-14T15:15:21 Z belgianbot Global Warming (CEOI18_glo) C++14
100 / 100
54 ms 5460 KB
#include <bits/stdc++.h>

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N, X; cin >> N >> X;
	
	vector <int> a (N);
	for (int i(0); i < N; i++)
		cin >> a[i];
	
	vector <int> pre(N), dp(N, INT_MAX);
	for (int i(0); i < N; i++) {
		auto it = lower_bound(dp.begin(), dp.end(), a[i] + X);
		int index = distance(dp.begin(), it);
		pre[i] = index;
		
		it = lower_bound(dp.begin(), dp.end(), a[i]);
		*it = a[i];
	}
	int ans(0);
	vector <int> suf(N, 0);
	for (int i(N - 1); i >= 0; i--) {
		int l(0), r(N - i), pos;
		while (l <= r) {
			int mid = l + (r - l) / 2;
			if (suf[mid] > a[i]) l = mid + 1;
			else {
				pos = mid;
				r = mid - 1;
			}
		}
		suf[pos] = a[i];
		ans = max(ans, pre[i] + pos + 1);
	}
	
	cout << ans << '\n';
		
	return 0;
}
			

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:36:25: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |   ans = max(ans, pre[i] + pos + 1);
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 5248 KB Output is correct
2 Correct 49 ms 5460 KB Output is correct
3 Correct 49 ms 5460 KB Output is correct
4 Correct 54 ms 5452 KB Output is correct
5 Correct 28 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1740 KB Output is correct
2 Correct 11 ms 1540 KB Output is correct
3 Correct 12 ms 1628 KB Output is correct
4 Correct 10 ms 1468 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 8 ms 1376 KB Output is correct
7 Correct 9 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2908 KB Output is correct
2 Correct 21 ms 2908 KB Output is correct
3 Correct 43 ms 5460 KB Output is correct
4 Correct 35 ms 4728 KB Output is correct
5 Correct 15 ms 2396 KB Output is correct
6 Correct 29 ms 4444 KB Output is correct
7 Correct 29 ms 5212 KB Output is correct
8 Correct 18 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 456 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 49 ms 5248 KB Output is correct
28 Correct 49 ms 5460 KB Output is correct
29 Correct 49 ms 5460 KB Output is correct
30 Correct 54 ms 5452 KB Output is correct
31 Correct 28 ms 4696 KB Output is correct
32 Correct 12 ms 1740 KB Output is correct
33 Correct 11 ms 1540 KB Output is correct
34 Correct 12 ms 1628 KB Output is correct
35 Correct 10 ms 1468 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 8 ms 1376 KB Output is correct
38 Correct 9 ms 1628 KB Output is correct
39 Correct 22 ms 2908 KB Output is correct
40 Correct 21 ms 2908 KB Output is correct
41 Correct 43 ms 5460 KB Output is correct
42 Correct 35 ms 4728 KB Output is correct
43 Correct 15 ms 2396 KB Output is correct
44 Correct 29 ms 4444 KB Output is correct
45 Correct 29 ms 5212 KB Output is correct
46 Correct 18 ms 2764 KB Output is correct
47 Correct 26 ms 2864 KB Output is correct
48 Correct 23 ms 2908 KB Output is correct
49 Correct 49 ms 5248 KB Output is correct
50 Correct 31 ms 4560 KB Output is correct
51 Correct 25 ms 3676 KB Output is correct
52 Correct 30 ms 4692 KB Output is correct
53 Correct 31 ms 4804 KB Output is correct
54 Correct 30 ms 5456 KB Output is correct
55 Correct 39 ms 5460 KB Output is correct