답안 #998182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998182 2024-06-13T11:34:09 Z jcelin Sparklers (JOI17_sparklers) C++14
100 / 100
41 ms 8136 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define X first
#define Y second
#define PB push_back
#define PPB pop_back
#define all(x) (x).begin(), (x).end()
 
typedef vector<int> vi; 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef long double ld;
 
const int MAXN = 1e6 + 7;
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ll INF = 1e18 + 7;
 
ll x[MAXN], n, k, t;
vll lef, rig;
vpll L, R, nl, nr;
 
bool okej(ll poc, vpll &vec){
	for(auto &y : vec){
		if(poc + y.Y < 0) return 0;
		poc += y.X;
	}
	return poc >= 0;
}


bool moze(ll csu, vpll L, vpll R){
	int li = 0, ri = 0;
	while(1){
		pll c1 = {-inf, -inf}, c2 = {-inf, -inf};
		
		if(li < (int)L.size()) c1 = L[li];
		if(ri < (int)R.size()) c2 = R[ri];
		
		if(c1.X == -inf and c2.X == -inf) return 1;
		
		if(csu + c1.Y >= 0){
			csu += c1.X;
			li++;
			continue;
		}
		
		if(csu + c2.Y >= 0){
			csu += c2.X;
			ri++;
			continue;
		}
		
		return 0;
	}
}

bool check(ll mid){
	lef.clear();
	rig.clear();
	L.clear();
	R.clear();
	nl.clear();
	nr.clear();
	
	ll sum = 0;
	for(int i=k; i<n; i++) rig.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2), sum += rig.back();
	for(int i=1; i<k; i++) lef.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2), sum += lef.back();
	reverse(all(lef));
	if(sum < 0) return 0;
	
	ll csu = 0, mi = 0;
	int ls = -1;
	for(int i=0; i<(int)rig.size(); i++){
		csu += rig[i];
		mi = min(mi, csu);
		if(csu >= 0){
			R.PB({csu, mi});
			csu = mi = 0;
			ls = i;
		}
	}
	
	csu = mi = 0;
	for(int i=(int)rig.size() - 1; i>ls; i--){
		csu -= rig[i];
		mi = min(mi, csu);
		if(csu >= 0){
			nr.PB({csu, mi});
			csu = mi = 0;
		}
	}
	
	
	csu = 0, mi = 0;
	ls = -1;
	for(int i=0; i<(int)lef.size(); i++){
		csu += lef[i];
		mi = min(mi, csu);
		if(csu >= 0){
			L.PB({csu, mi});
			csu = mi = 0;
			ls = i;
		}
	}
	
	csu = mi = 0;
	for(int i=(int)lef.size() - 1; i>ls; i--){
		csu -= lef[i];
		mi = min(mi, csu);
		if(csu >= 0){
			nl.PB({csu, mi});
			csu = mi = 0;
		}
	}
	
	return moze(0, L, R) and moze(sum, nl, nr);
}
 
void solve(){
	cin >> n >> k >> t;
	for(int i=1; i<=n; i++) cin >> x[i], x[i] *= 2;
	
	int lo = 0, hi = ((1e9 + 1) / t) + 1, ret = -1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		if(check(mid)) hi = mid - 1, ret = mid;
		else lo = mid + 1;
	}
	cout << ret << "\n";
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt = 1;
	//cin >> t;
	while(tt--) solve();
	return 0;
}

/*
-15708 2615 22272 -6638 -35674 -50958 41359 -1318 
-33710 -40703 4522 12061
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 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 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 464 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 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 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 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 464 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 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 472 KB Output is correct
34 Correct 1 ms 472 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 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 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 464 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 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 472 KB Output is correct
34 Correct 1 ms 472 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 25 ms 6344 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 8 ms 1584 KB Output is correct
44 Correct 31 ms 7928 KB Output is correct
45 Correct 34 ms 7368 KB Output is correct
46 Correct 36 ms 8008 KB Output is correct
47 Correct 36 ms 7888 KB Output is correct
48 Correct 34 ms 7360 KB Output is correct
49 Correct 31 ms 7256 KB Output is correct
50 Correct 33 ms 7512 KB Output is correct
51 Correct 34 ms 7892 KB Output is correct
52 Correct 34 ms 8036 KB Output is correct
53 Correct 33 ms 7404 KB Output is correct
54 Correct 41 ms 8016 KB Output is correct
55 Correct 32 ms 7524 KB Output is correct
56 Correct 31 ms 8116 KB Output is correct
57 Correct 36 ms 8136 KB Output is correct
58 Correct 35 ms 7256 KB Output is correct
59 Correct 40 ms 6756 KB Output is correct
60 Correct 31 ms 8016 KB Output is correct
61 Correct 35 ms 7972 KB Output is correct
62 Correct 30 ms 7892 KB Output is correct
63 Correct 31 ms 7764 KB Output is correct
64 Correct 32 ms 7524 KB Output is correct
65 Correct 31 ms 7256 KB Output is correct
66 Correct 39 ms 7504 KB Output is correct
67 Correct 31 ms 7504 KB Output is correct
68 Correct 32 ms 8016 KB Output is correct
69 Correct 32 ms 8016 KB Output is correct