답안 #321177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321177 2020-11-11T11:29:00 Z Mounir Global Warming (CEOI18_glo) C++14
100 / 100
452 ms 25812 KB
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(v) v.begin(), v.end()
#define pb push_back
#define int long long
using namespace std;

const int N = 1 << 19;
int dynMax[2 * N][2];

int getMax(int gauche, int droite, int mod){
	if (gauche > droite) return 0;
	if (gauche%2 == 1) return max(dynMax[gauche][mod], getMax(gauche + 1, droite, mod));
	if (droite%2 == 0) return max(dynMax[droite][mod], getMax(gauche, droite - 1, mod));
	return getMax(gauche/2, droite/2, mod);
}

void update(int ind, int val, int mod){
	for (; ind > 0; ind /= 2)
		chmax(dynMax[ind][mod], val);
}

signed main(){
	int nVals, toAdd; cin >> nVals >> toAdd;
	vector<int> triees, vals(nVals), pointeur(nVals);
	map<int, int> conversion;
	for (int& val : vals) cin >> val, triees.pb(val);
	sort(all(triees));
	pointeur[nVals - 1] = nVals - 1;
	for (int ind = nVals - 2; ind >= 0; --ind){
		pointeur[ind] = pointeur[ind + 1];
		while (pointeur[ind] > ind && triees[pointeur[ind]] - toAdd >= triees[ind])
			--pointeur[ind];
	}
	
	for (int ind = 0; ind < nVals; ++ind)conversion[triees[ind]] = ind;
	
	for (int& val : vals) val = conversion[val];
	
	for (int ind = 0; ind < nVals; ++ind){
		for (int xAjoute = 1; xAjoute >= 0; --xAjoute){
			update(N + vals[ind], getMax(N, N + vals[ind] - 1, xAjoute) + 1, xAjoute);
			if (xAjoute == 1 && toAdd != 0) update(N + vals[ind], getMax(N, N + pointeur[vals[ind]], 0) + 1, xAjoute);
			//cout << dynMax[N + vals[ind]][xAjoute] << " " << vals[ind] << " " << pointeur[ind] << endl;
		}
	//	cout << endl;
	}
	
	cout << max(dynMax[1][0], dynMax[1][1]) << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 425 ms 24192 KB Output is correct
2 Correct 403 ms 24148 KB Output is correct
3 Correct 418 ms 24020 KB Output is correct
4 Correct 420 ms 24020 KB Output is correct
5 Correct 168 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 6492 KB Output is correct
2 Correct 78 ms 6492 KB Output is correct
3 Correct 76 ms 6424 KB Output is correct
4 Correct 46 ms 4220 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 44 ms 4828 KB Output is correct
7 Correct 68 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 12376 KB Output is correct
2 Correct 176 ms 12500 KB Output is correct
3 Correct 439 ms 24112 KB Output is correct
4 Correct 170 ms 14676 KB Output is correct
5 Correct 107 ms 12248 KB Output is correct
6 Correct 195 ms 22996 KB Output is correct
7 Correct 214 ms 22868 KB Output is correct
8 Correct 135 ms 12248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 425 ms 24192 KB Output is correct
28 Correct 403 ms 24148 KB Output is correct
29 Correct 418 ms 24020 KB Output is correct
30 Correct 420 ms 24020 KB Output is correct
31 Correct 168 ms 14676 KB Output is correct
32 Correct 76 ms 6492 KB Output is correct
33 Correct 78 ms 6492 KB Output is correct
34 Correct 76 ms 6424 KB Output is correct
35 Correct 46 ms 4220 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 44 ms 4828 KB Output is correct
38 Correct 68 ms 6492 KB Output is correct
39 Correct 171 ms 12376 KB Output is correct
40 Correct 176 ms 12500 KB Output is correct
41 Correct 439 ms 24112 KB Output is correct
42 Correct 170 ms 14676 KB Output is correct
43 Correct 107 ms 12248 KB Output is correct
44 Correct 195 ms 22996 KB Output is correct
45 Correct 214 ms 22868 KB Output is correct
46 Correct 135 ms 12248 KB Output is correct
47 Correct 180 ms 13144 KB Output is correct
48 Correct 181 ms 13144 KB Output is correct
49 Correct 452 ms 25804 KB Output is correct
50 Correct 178 ms 15828 KB Output is correct
51 Correct 157 ms 15700 KB Output is correct
52 Correct 230 ms 25192 KB Output is correct
53 Correct 208 ms 25144 KB Output is correct
54 Correct 230 ms 25812 KB Output is correct
55 Correct 304 ms 25812 KB Output is correct