Submission #995725

# Submission time Handle Problem Language Result Execution time Memory
995725 2024-06-09T19:49:34 Z jcelin Sparklers (JOI17_sparklers) C++14
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define PB push_back
#define PPB pop_back
#define all(x) (x).begin(), (x).end()

typedef vector<int> vi; 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef long double ld;

const int MAXN = 47;
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ll INF = 1e18 + 7;

ll x[MAXN], n, k, t;
vll lef, rig;
vpll L, R;

bool okej(ll poc, vpll &vec){
	for(auto &y : vec){
		if(poc + y.Y < 0) return 0;
		poc += y.X;
	}
	return poc >= 0;
}

bool check(ll mid){
	lef.clear();
	rig.clear();
	L.clear();
	R.clear();
	for(int i=k; i<n; i++) rig.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2);
	for(int i=1; i<k; i++) lef.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2);
	reverse(all(lef));
	
	ll csu = 0, mi = 0;
	for(auto &y : rig){
		csu += y;
		mi = min(mi, csu);
		if(csu >= 0){
			R.PB({csu, mi});
			csu = mi = 0;
		}
	}
	if(csu or mi) R.PB({csu, mi});
	
	csu = mi = 0;
	for(auto &y : lef){
		csu += y;
		mi = min(mi, csu);
		if(csu >= 0){
			L.PB({csu, mi});
			csu = mi = 0;
		}
	}
	if(csu or mi) L.PB({csu, mi});
	
	int li = 0, ri = 0;
	csu = 0;
	while(1){
		pll c1 = {-inf, -inf}, c2 = {-inf, -inf};
		
		if(li < (int)L.size()) c1 = L[li];
		if(ri < (int)R.size()) c2 = R[ri];
		
		if(c1.X < 0 and c2.X < 0) break;
		
		if(c1.X >= 0 and csu + c1.Y >= 0){
			csu += c1.X;
			li++;
			continue;
		}
		
		if(c2.X >= 0 and csu + c2.Y >= 0){
			csu += c2.X;
			ri++;
			continue;
		}
		
		return 0;
	}
	
	vpll vec;
	if(li < (int)L.size()) vec.PB(L[li]);
	if(ri < (int)R.size()) vec.PB(R[ri]);
	
	if(okej(csu, vec)) return 1;
	reverse(all(vec));
	return okej(csu, vec);
}

void solve(){
	cin >> n >> k >> t;
	for(int i=1; i<=n; i++) cin >> x[i], x[i] *= 2;
	
	int lo = 1, hi = ((1e9 + 1) / t) + 1, ret = -1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		if(check(mid)) hi = mid - 1, ret = mid;
		else lo = mid + 1;
	}
	cout << ret << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt = 1;
	//cin >> t;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -