답안 #578494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578494 2022-06-17T04:53:17 Z alireza_kaviani Sparklers (JOI17_sparklers) C++17
100 / 100
57 ms 4840 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)      (x).begin(),(x).end()
#define X           first
#define Y           second
#define sep         ' '
#define endl        '\n'
#define SZ(x)       ll(x.size())

const ll MAXN = 2e5 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;

ll n , k , t , A[MAXN];
vector<ll> L , R;

int check(ll s){
	int n = SZ(L) , m = SZ(R);
	vector<ll> x = {0} , y = {0};
	for(int i = 0 ; i < n ; i++){
		x.push_back(L[i] - 2 * s * t * (i + 1));
	}
	for(int i = 0 ; i < m ; i++){
		y.push_back(R[i] - 2 * s * t * (i + 1));
	}
	ll xpos = min_element(all(x)) - x.begin();
	ll ypos = min_element(all(y)) - y.begin();
	ll xptr = 0 , yptr = 0 , xmn = 0 , ymn = 0;
	while(xptr <= xpos || yptr <= ypos){
		if(xptr <= xpos && x[xptr] + ymn <= 0){
			xmn = min(xmn , x[xptr++]);
			continue;
		}
		if(yptr <= ypos && xmn + y[yptr] <= 0){
			ymn = min(ymn , y[yptr++]);
			continue;
		}
		break;
	}
	if(xptr <= xpos || yptr <= ypos)	return 0;
	xptr = n , yptr = m , xmn = x.back() , ymn = y.back();
	while(xptr >= xpos || yptr >= ypos){
		if(xptr >= xpos && x[xptr] + ymn <= 0){
			xmn = min(xmn , x[xptr--]);
			continue;
		}
		if(yptr >= ypos && xmn + y[yptr] <= 0){
			ymn = min(ymn , y[yptr--]);
			continue;
		}
		break;
	}
	return (xptr < xpos && yptr < ypos);
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	cin >> n >> k >> t;
	for(int i = 1 ; i <= n ; i++){
		cin >> A[i];
	}
	for(int i = k - 1 ; i >= 1 ; i--){
		L.push_back(A[k] - A[i]);
	}
	for(int i = k + 1 ; i <= n ; i++){
		R.push_back(A[i] - A[k]);
	}
	int l = -1 , r = MOD;
	while(r - l > 1){
		int mid = l + r >> 1;
		if(check(mid))	r = mid;
		else	l = mid;
	}
	cout << r << endl;

    return 0;
}
/*

*/

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:77:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |   int mid = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 280 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 280 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 280 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 29 ms 2992 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 10 ms 1096 KB Output is correct
44 Correct 45 ms 4840 KB Output is correct
45 Correct 44 ms 4252 KB Output is correct
46 Correct 46 ms 4744 KB Output is correct
47 Correct 52 ms 4724 KB Output is correct
48 Correct 47 ms 4148 KB Output is correct
49 Correct 42 ms 4780 KB Output is correct
50 Correct 42 ms 4212 KB Output is correct
51 Correct 45 ms 4776 KB Output is correct
52 Correct 38 ms 4572 KB Output is correct
53 Correct 57 ms 4768 KB Output is correct
54 Correct 35 ms 4600 KB Output is correct
55 Correct 44 ms 4240 KB Output is correct
56 Correct 53 ms 4732 KB Output is correct
57 Correct 57 ms 4704 KB Output is correct
58 Correct 55 ms 4236 KB Output is correct
59 Correct 41 ms 3392 KB Output is correct
60 Correct 46 ms 4560 KB Output is correct
61 Correct 35 ms 4464 KB Output is correct
62 Correct 49 ms 4768 KB Output is correct
63 Correct 47 ms 4516 KB Output is correct
64 Correct 54 ms 4228 KB Output is correct
65 Correct 42 ms 4256 KB Output is correct
66 Correct 47 ms 4112 KB Output is correct
67 Correct 45 ms 4224 KB Output is correct
68 Correct 43 ms 4620 KB Output is correct
69 Correct 47 ms 4640 KB Output is correct