답안 #768897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768897 2023-06-28T20:38:04 Z 1ne Global Warming (CEOI18_glo) C++14
100 / 100
57 ms 14800 KB
/*
*  author : Apiram                  
*  created: 29.06.2023 01:29:41
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,x;cin>>n>>x;
	vector<long long>arr(n);
	for (int i = 0;i<n;++i){
		cin>>arr[i];
	}
	const long long inf = 1e12;
	int ans = 0;
	vector<vector<long long>>dp(n + 1,vector<long long>(2,inf));
	for (int i = 0;i<n;++i){
		int left = 0,right = i - 1;
		int pos = -1;
		while(left<=right){
			int mid = (left + right)>>1;
			if (dp[mid][0] < arr[i] + x){
				//cout<<dp[mid][0]<<" "<<"check"<<" "<<mid<<'\n';
				pos = mid;
				left = mid + 1;
			}
			else if (dp[mid][1] < arr[i]){
				pos = mid;
				left = mid + 1;
			}
			else right = mid - 1;
		}
		ans = max(pos + 2,ans);
		dp[pos + 1][1] = min(dp[pos + 1][1],arr[i]);
		//cout<<pos<<'\n';
		left = 0,right = i - 1;
		pos = -1;	
		while(left<=right){
			int mid = (left + right)>>1;
			if (dp[mid][0] < arr[i]){
				pos = mid;
				left = mid + 1;
			}	
			else right = mid - 1;
		}
		dp[pos + 1][0] = min(arr[i],dp[pos + 1][0]);
		ans = max(ans,pos + 2);		
		//cout<<pos<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 316 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
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12780 KB Output is correct
2 Correct 50 ms 12756 KB Output is correct
3 Correct 57 ms 12768 KB Output is correct
4 Correct 51 ms 12780 KB Output is correct
5 Correct 41 ms 12724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3412 KB Output is correct
2 Correct 12 ms 3912 KB Output is correct
3 Correct 21 ms 3908 KB Output is correct
4 Correct 11 ms 3412 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 3668 KB Output is correct
7 Correct 15 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 6484 KB Output is correct
2 Correct 25 ms 6484 KB Output is correct
3 Correct 51 ms 12756 KB Output is correct
4 Correct 35 ms 12768 KB Output is correct
5 Correct 14 ms 6484 KB Output is correct
6 Correct 41 ms 12180 KB Output is correct
7 Correct 36 ms 12228 KB Output is correct
8 Correct 21 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 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 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 316 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 50 ms 12780 KB Output is correct
28 Correct 50 ms 12756 KB Output is correct
29 Correct 57 ms 12768 KB Output is correct
30 Correct 51 ms 12780 KB Output is correct
31 Correct 41 ms 12724 KB Output is correct
32 Correct 12 ms 3412 KB Output is correct
33 Correct 12 ms 3912 KB Output is correct
34 Correct 21 ms 3908 KB Output is correct
35 Correct 11 ms 3412 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 7 ms 3668 KB Output is correct
38 Correct 15 ms 3924 KB Output is correct
39 Correct 32 ms 6484 KB Output is correct
40 Correct 25 ms 6484 KB Output is correct
41 Correct 51 ms 12756 KB Output is correct
42 Correct 35 ms 12768 KB Output is correct
43 Correct 14 ms 6484 KB Output is correct
44 Correct 41 ms 12180 KB Output is correct
45 Correct 36 ms 12228 KB Output is correct
46 Correct 21 ms 6484 KB Output is correct
47 Correct 25 ms 7508 KB Output is correct
48 Correct 25 ms 7508 KB Output is correct
49 Correct 52 ms 14772 KB Output is correct
50 Correct 36 ms 13920 KB Output is correct
51 Correct 33 ms 10636 KB Output is correct
52 Correct 39 ms 14044 KB Output is correct
53 Correct 35 ms 14020 KB Output is correct
54 Correct 40 ms 14680 KB Output is correct
55 Correct 46 ms 14800 KB Output is correct