답안 #864765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864765 2023-10-23T14:49:54 Z manizare Sparklers (JOI17_sparklers) C++14
100 / 100
107 ms 13284 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
 
constexpr ll inf = 1e18, N = 2e5 + 10, mod = 1e9 + 7, pr = 1000696969;
 
int n, k;
ll x[N], spA[N], spB[N];
 
bool valid(vector<ll> vc1, vector<ll> vc2) {
	int sa = Sz(vc1), sb = Sz(vc2);
	if(vc1[sa - 1] + vc2[sb - 1] < 0) return 0;
 
	int pa = 0, pb = 0, main_pa = 0;
		
	while((pa < sa - 1) || (pb < sb - 1)) {
		if(vc1[pa] + vc2[pb] < 0) return 0;
		if(pa == sa - 1) {
			pb++;
			continue;
		}
		if(pb == sb - 1) {
			pa++;
			continue;
		}
		int fr = pa;
		main_pa = max(main_pa, pa + 1);
		for(; main_pa < sa; main_pa++) {
			if(vc1[main_pa] + vc2[pb] < 0) break;
			if(vc1[main_pa] - vc1[pa] >= 0) {
				pa = main_pa;
				continue;
			}
		}
		if(pa != fr) continue;
 
		int main_pb = pb;
		for(int i = main_pb + 1; i < sb; i++) {
			if(vc2[i] + vc1[pa] < 0) break;
			if(vc2[i] - vc2[pb] >= 0) {
				main_pb = i;
				break;
			}
		}
 
		if(main_pb > pb) {
			pb = main_pb;
			continue;
		}
 
 
		return 0;
	}
 
	return 1;
}
 
bool okay(ll t) {
	if(t > 1e9) return 1;
	vector<ll> A = {t}, B;
	for(int i = k + 1; i <= n; i++) {
		A.push_back(-(x[i] - x[i - 1]));
		A.push_back(t);
	}
	for(int i = k - 1; i > 0; i--) {
		B.push_back(-(x[i + 1] - x[i]));
		B.push_back(t);
	}
 
	spA[0] = spA[0] = 0;
	for(int i = 0; i < Sz(A); i++) spA[i + 1] = spA[i] + A[i];
	for(int i = 0; i < Sz(B); i++) spB[i + 1] = spB[i] + B[i];
 
	int inda = max_element(spA, spA + Sz(A) + 1) - spA;
	int indb = max_element(spB, spB + Sz(B) + 1) - spB;
 
	vector<ll> lA, rA, lB, rB;
	for(int i = 0; i <= inda; i++) lA.push_back(spA[i]);
	for(int i = inda; i <= Sz(A); i++) rA.push_back(spA[i]);
	for(int i = 0; i <= indb; i++) lB.push_back(spB[i]);
	for(int i = indb; i <= Sz(B); i++) rB.push_back(spB[i]);
 
	reverse(All(rA)), reverse(All(rB));
	
	return valid(lA, lB) && valid(rA, rB);
}
 
int main() {
    ios :: sync_with_stdio(0), cin.tie(0);
	
	ll t; 
	cin >>n >>k >>t;
	for(int i = 1; i <= n; i++) cin >>x[i];
	
 
	int l = 0, r = 1e9;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(okay(1ll * t * mid * 2)) r = mid;
		else l = mid + 1;
	}
 
	cout<<l;
 
 
 
    return 0;
}
 

Compilation message

sparklers.cpp: In function 'bool okay(ll)':
sparklers.cpp:79:9: warning: operation on 'spA[0]' may be undefined [-Wsequence-point]
   79 |  spA[0] = spA[0] = 0;
      |  ~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 51 ms 9612 KB Output is correct
42 Correct 3 ms 4780 KB Output is correct
43 Correct 14 ms 6048 KB Output is correct
44 Correct 84 ms 11756 KB Output is correct
45 Correct 78 ms 11248 KB Output is correct
46 Correct 76 ms 12676 KB Output is correct
47 Correct 74 ms 13268 KB Output is correct
48 Correct 79 ms 11360 KB Output is correct
49 Correct 94 ms 11812 KB Output is correct
50 Correct 75 ms 11960 KB Output is correct
51 Correct 75 ms 12512 KB Output is correct
52 Correct 107 ms 13284 KB Output is correct
53 Correct 93 ms 11828 KB Output is correct
54 Correct 95 ms 12972 KB Output is correct
55 Correct 77 ms 11316 KB Output is correct
56 Correct 77 ms 12752 KB Output is correct
57 Correct 86 ms 11912 KB Output is correct
58 Correct 81 ms 11692 KB Output is correct
59 Correct 77 ms 9884 KB Output is correct
60 Correct 94 ms 13060 KB Output is correct
61 Correct 95 ms 12904 KB Output is correct
62 Correct 74 ms 12704 KB Output is correct
63 Correct 95 ms 12888 KB Output is correct
64 Correct 71 ms 11040 KB Output is correct
65 Correct 74 ms 11412 KB Output is correct
66 Correct 76 ms 11172 KB Output is correct
67 Correct 76 ms 11420 KB Output is correct
68 Correct 95 ms 13076 KB Output is correct
69 Correct 96 ms 13152 KB Output is correct