답안 #386158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386158 2021-04-05T20:32:58 Z pit4h Sparklers (JOI17_sparklers) C++14
100 / 100
96 ms 3436 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

bool solve(int n, int k, ll t, vector<ll> x) {
	int l = k, r = k, L=k, R = k;	
	deque<int> monoL, monoR, MonoL, MonoR;
	monoL.push_back(k), monoR.push_back(k);
	MonoL.push_back(k), MonoR.push_back(k);
	for(int i=0; i<n; ++i) {
		while(l > 0 && (R-l+1) * t - (x[R] - x[l-1]) / 2 >= 0LL) {
			l--;
			while(monoL.size() && (k-l) * t + x[l] / 2 < (k-monoL.back()) * t + x[monoL.back()] / 2) {
				monoL.pop_back();
			}
			monoL.push_back(l);
			while(MonoL.size() && (k-l) * t + x[l] / 2 > (k-MonoL.back()) * t + x[MonoL.back()] / 2) {
				MonoL.pop_back();
			}
			MonoL.push_back(l);
			if((k-l) * t + x[l] / 2 > (k-L) * t + x[L] / 2) {
				L = l;
			}
		}
		while(r < n-1 && (r-L+1) * t - (x[r+1] - x[L]) / 2 >= 0LL) {
			r++;
			while(monoR.size() && (r-k) * t - x[r] / 2 < (monoR.back()-k) * t - x[monoR.back()] / 2) {
				monoR.pop_back();	
			}
			monoR.push_back(r);
			while(MonoR.size() && (r-k) * t - x[r] / 2 > (MonoR.back()-k) * t - x[MonoR.back()] / 2) {
				MonoR.pop_back();	
			}
			MonoR.push_back(r);
			if((r-k) * t - x[r] / 2 > (R-k) * t - x[R] / 2) {
				R = r;
			}
		}
	}
	if(l > 0 || r < n-1) return false;
	
	while(monoL.front() > L) monoL.pop_front();
	while(monoR.front() < R) monoR.pop_front();
	while(MonoL.size() && MonoL.front() >= L) MonoL.pop_front();
	while(MonoR.size() && MonoR.front() <= R) MonoR.pop_front();

	for(int i=0; i<n; ++i) {
		while(L > 0 && (k-MonoL.front()) * t + x[MonoL.front()] / 2 + (monoR.front()-k) * t - x[monoR.front()] / 2 >= 0LL) {
			L = MonoL.front();			
			while(monoL.front() > L) monoL.pop_front();
			while(MonoL.size() && MonoL.front() >= L) MonoL.pop_front();
		}
		while(R < n-1 && (MonoR.front()-k) * t - x[MonoR.front()] / 2 + (k-monoL.front()) * t + x[monoL.front()] / 2 >= 0LL) {
			R = MonoR.front();
			while(monoR.front() < R) monoR.pop_front();
			while(MonoR.size() && MonoR.front() <= R) MonoR.pop_front();
		}
	}
	return L == 0 && R == n-1;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	ll t;
	cin>>n>>k>>t;
	k--;
	t *= 2LL;
	vector<ll> x(n);
	for(int i=0; i<n; ++i) {
		cin>>x[i];
		x[i] *= 2LL;
	}

	ll lo = 0, hi = 1e10 / t + 1;
	while(lo<=hi) {
		ll mid = (lo+hi)/2LL;
		if(solve(n, k, t*mid, x)) {
			hi = mid-1;
		}
		else {
			lo = mid+1;
		}
	}
	cout<<hi+1<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 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 384 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 2 ms 392 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 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 384 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 2 ms 392 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 364 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 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 384 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 2 ms 392 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 2 ms 364 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 58 ms 2288 KB Output is correct
42 Correct 3 ms 364 KB Output is correct
43 Correct 17 ms 876 KB Output is correct
44 Correct 91 ms 3308 KB Output is correct
45 Correct 91 ms 3308 KB Output is correct
46 Correct 80 ms 3308 KB Output is correct
47 Correct 85 ms 3308 KB Output is correct
48 Correct 84 ms 3308 KB Output is correct
49 Correct 81 ms 3324 KB Output is correct
50 Correct 82 ms 3308 KB Output is correct
51 Correct 90 ms 3308 KB Output is correct
52 Correct 79 ms 3308 KB Output is correct
53 Correct 93 ms 3308 KB Output is correct
54 Correct 83 ms 3308 KB Output is correct
55 Correct 96 ms 3308 KB Output is correct
56 Correct 83 ms 3308 KB Output is correct
57 Correct 88 ms 3436 KB Output is correct
58 Correct 95 ms 3308 KB Output is correct
59 Correct 85 ms 2880 KB Output is correct
60 Correct 84 ms 3308 KB Output is correct
61 Correct 77 ms 3180 KB Output is correct
62 Correct 85 ms 3308 KB Output is correct
63 Correct 81 ms 3308 KB Output is correct
64 Correct 80 ms 3308 KB Output is correct
65 Correct 83 ms 3308 KB Output is correct
66 Correct 85 ms 3308 KB Output is correct
67 Correct 80 ms 3308 KB Output is correct
68 Correct 94 ms 3308 KB Output is correct
69 Correct 81 ms 3308 KB Output is correct