Submission #132808

# Submission time Handle Problem Language Result Execution time Memory
132808 2019-07-19T15:55:04 Z sebinkim Sparklers (JOI17_sparklers) C++14
0 / 100
3 ms 380 KB
#include <bits/stdc++.h>

using namespace std;

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

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

bool check(ll v)
{
	ll i, s;
	
	L.clear(); R.clear();
	
	for(i=1; i<k; i++){
		L.push_back(2 * t * v - X[i + 1] + X[i]);
	}
	
	for(i=n; i>k; i--){
		R.push_back(2 * t * v - X[i] + X[i - 1]);
	}
	
	for(s=0; !L.empty() || !R.empty(); ){
		if(!L.empty() && (R.empty() || L.back() > R.back())){
			s += L.back(); L.pop_back();
		}
		else{
			s += R.back(), R.pop_back();
		}
		if(s < 0) return 0;
	}
	
	return 1;
}

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:53:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s + e >> 1)) e = (s + e >> 1) - 1;
            ~~^~~
sparklers.cpp:53:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(check(s + e >> 1)) e = (s + e >> 1) - 1;
                              ~~^~~
sparklers.cpp:54: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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 3 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 3 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 3 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -