답안 #825952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825952 2023-08-15T09:29:58 Z sentheta Global Warming (CEOI18_glo) C++17
100 / 100
67 ms 6960 KB
// author : sentheta aka vanwij
#ifdef VANWIJ
	#include"/home/user/code/bits/stdc++.h"
	#define DBG 1
#else
	#include"bits/stdc++.h"
	#define DBG 0
#endif
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)

#define cerr if(DBG) cout
#define dbg(x) {cerr << "?" << #x << " : " << (x) << endl << flush;}

#define int long long
// const Int MOD = 1e9+7;
const Int MOD = 998244353;
Int bpow(Int a,Int b){
	Int ret = 1;
	for(;b; a=a*a%MOD,b/=2) if(b&1) ret = ret*a%MOD;
	return ret;
}
Int inv(Int a){return bpow(a,MOD-2);}

void solve(); int TC, ALLTC;
signed main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(7);
	// cin >> ALLTC; for(TC=1; TC<=ALLTC; TC++) solve(); return 0;
	solve();
}








const int N = 2e5+5;
const int LN = 18;
const int INF = 1e18;

int n, x;
int a[N];


int dp[N];

int suf[N];



void solve(){
	
	cin >> n >> x;
	
	rep(i,1,n+1){
		cin >> a[i];
	}
	
	int ans = 0;
	
	// dp[len] = max possible beginning of length len
	rep(i,0,N) dp[i] = -INF;
	dp[0] = INF;
	for(int i=n; i>=1; i--){
		// LIS
		int len = 0;
		for(int J=1<<LN; J; J/=2)
			if(len+J<n && a[i]<dp[len+J]) len+=J;
		len++;
		dp[len] = max(dp[len], a[i]);
		
		suf[i] = max(suf[i], len);
	}
	ans = suf[1];
	
	
	
	// dp[len] = min possible ending of length len
	rep(i,0,N) dp[i] = INF;
	dp[0] = -INF;
	for(int i=1; i<=n-1; i++){
		dbg(i);
		
		// LIS
		int len = 0;
		for(int J=1<<LN; J; J/=2)
			if(len+J<n && dp[len+J]<a[i]) len+=J;
		len++;
		dp[len] = min(dp[len], a[i]);
		dbg(len);
		
		// add X to suffix
		len = 0;
		for(int J=1<<LN; J; J/=2)
			if(len+J<n && dp[len+J] < a[i+1]+x) len+=J;
		ans = max(ans, len+suf[i+1]);
		dbg(len);
	}
	
	cout << ans << nl;
	
	

	
	
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1864 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1864 KB Output is correct
16 Correct 1 ms 1864 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1864 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1864 KB Output is correct
16 Correct 1 ms 1864 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 1864 KB Output is correct
23 Correct 1 ms 1872 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 6924 KB Output is correct
2 Correct 50 ms 6872 KB Output is correct
3 Correct 43 ms 6860 KB Output is correct
4 Correct 50 ms 6820 KB Output is correct
5 Correct 44 ms 6168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3092 KB Output is correct
3 Correct 11 ms 3156 KB Output is correct
4 Correct 14 ms 2956 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 9 ms 2868 KB Output is correct
7 Correct 10 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4424 KB Output is correct
2 Correct 32 ms 4324 KB Output is correct
3 Correct 47 ms 6856 KB Output is correct
4 Correct 43 ms 6104 KB Output is correct
5 Correct 28 ms 3940 KB Output is correct
6 Correct 46 ms 6032 KB Output is correct
7 Correct 63 ms 6700 KB Output is correct
8 Correct 20 ms 4376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 1 ms 1868 KB Output is correct
13 Correct 1 ms 1864 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1864 KB Output is correct
16 Correct 1 ms 1864 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 1864 KB Output is correct
23 Correct 1 ms 1872 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 55 ms 6924 KB Output is correct
28 Correct 50 ms 6872 KB Output is correct
29 Correct 43 ms 6860 KB Output is correct
30 Correct 50 ms 6820 KB Output is correct
31 Correct 44 ms 6168 KB Output is correct
32 Correct 10 ms 3156 KB Output is correct
33 Correct 14 ms 3092 KB Output is correct
34 Correct 11 ms 3156 KB Output is correct
35 Correct 14 ms 2956 KB Output is correct
36 Correct 1 ms 1868 KB Output is correct
37 Correct 9 ms 2868 KB Output is correct
38 Correct 10 ms 3180 KB Output is correct
39 Correct 20 ms 4424 KB Output is correct
40 Correct 32 ms 4324 KB Output is correct
41 Correct 47 ms 6856 KB Output is correct
42 Correct 43 ms 6104 KB Output is correct
43 Correct 28 ms 3940 KB Output is correct
44 Correct 46 ms 6032 KB Output is correct
45 Correct 63 ms 6700 KB Output is correct
46 Correct 20 ms 4376 KB Output is correct
47 Correct 25 ms 4308 KB Output is correct
48 Correct 32 ms 4308 KB Output is correct
49 Correct 52 ms 6924 KB Output is correct
50 Correct 62 ms 6168 KB Output is correct
51 Correct 47 ms 5088 KB Output is correct
52 Correct 60 ms 6268 KB Output is correct
53 Correct 49 ms 6208 KB Output is correct
54 Correct 67 ms 6956 KB Output is correct
55 Correct 51 ms 6960 KB Output is correct