Submission #133378

# Submission time Handle Problem Language Result Execution time Memory
133378 2019-07-20T13:00:33 Z sebinkim Sparklers (JOI17_sparklers) C++14
100 / 100
32 ms 2940 KB
#include <bits/stdc++.h>

using namespace std;

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

vector <pll> L, R;
ll X[101010], D[101010];
ll n, k, t;

bool check(ll v)
{
	ll i, j, l, r, f, l1, l2, r1, r2;
	
	for(i=1; i<=n; i++){
		D[i] = 2 * v * t * i - X[i];
	}
	
	if(D[1] > D[n]) return 0;
	
	for(l=k, r=k, i=k-1, j=k+1, f=0; ; f=0){
		for(; i >= 1 && D[i] > D[l] && D[i] <= D[r]; i--);
		for(; j <= n && D[j] < D[r] && D[j] >= D[l]; j++);
		
		if(i >= 1 && D[i] <= D[l]) l = i --, f = 1;
		if(j <= n && D[j] >= D[r]) r = j ++, f = 1;
		if(!f) break;
	}
	
	l1 = l; r1 = r;
//	cout << l1 << " " << r1 << "\n";
	
	for(l=1, r=n, i=2, j=n-1, f=0; ; f=0){
		for(; i <= k && D[i] > D[l] && D[i] <= D[r]; i++);
		for(; j >= k && D[j] < D[r] && D[j] >= D[l]; j--);
		
		if(i <= k && D[i] <= D[l]) l = i ++, f = 1;
		if(j >= k && D[j] >= D[r]) r = j --, f = 1;
		if(!f) break;
	}
	
	l2 = l; r2 = r;
//	cout << l2 << " " << r2 << "\n";
	
	return (l1 <= l2) && (r2 <= r1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll i, s, e;
	
	cin >> n >> k >> t;
	
	for(i=1; i<=n; i++){
		cin >> X[i];
	}
		
	for(s=0, e=1e12/t; s<=e; ){
		if(check(s + e >> 1)) e = (s + e >> 1) - 1;
		else s = (s + e >> 1) + 1;
	}
	
	cout << e + 1 << "\n";
	
	return 0;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:63:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s + e >> 1)) e = (s + e >> 1) - 1;
            ~~^~~
sparklers.cpp:63:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s + e >> 1)) e = (s + e >> 1) - 1;
                              ~~^~~
sparklers.cpp:64:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else s = (s + e >> 1) + 1;
             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 372 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 372 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 20 ms 2040 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 7 ms 760 KB Output is correct
44 Correct 29 ms 2908 KB Output is correct
45 Correct 29 ms 2808 KB Output is correct
46 Correct 31 ms 2808 KB Output is correct
47 Correct 32 ms 2808 KB Output is correct
48 Correct 30 ms 2808 KB Output is correct
49 Correct 29 ms 2836 KB Output is correct
50 Correct 30 ms 2936 KB Output is correct
51 Correct 30 ms 2808 KB Output is correct
52 Correct 30 ms 2808 KB Output is correct
53 Correct 30 ms 2940 KB Output is correct
54 Correct 32 ms 2808 KB Output is correct
55 Correct 29 ms 2808 KB Output is correct
56 Correct 30 ms 2936 KB Output is correct
57 Correct 29 ms 2808 KB Output is correct
58 Correct 29 ms 2936 KB Output is correct
59 Correct 23 ms 2296 KB Output is correct
60 Correct 28 ms 2936 KB Output is correct
61 Correct 28 ms 2808 KB Output is correct
62 Correct 28 ms 2936 KB Output is correct
63 Correct 30 ms 2936 KB Output is correct
64 Correct 30 ms 2912 KB Output is correct
65 Correct 30 ms 2936 KB Output is correct
66 Correct 28 ms 2808 KB Output is correct
67 Correct 29 ms 2836 KB Output is correct
68 Correct 29 ms 2936 KB Output is correct
69 Correct 28 ms 2936 KB Output is correct