Submission #373681

# Submission time Handle Problem Language Result Execution time Memory
373681 2021-03-05T12:19:40 Z Kevin_Zhang_TW Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;

const ll inf = 1ll << 55;

int n, k, T;
int pos[MAX_N];

ll pf[MAX_N], suf[MAX_N];

bool valid(ll S) {

	pf[0] = inf, suf[n+1] = -inf;

	for (int i = 1;i <= n;++i) 
		pf[i] = min<ll>(pos[i], pf[i-1] + S * T);

	for (int i = n;i >= 1;--i) 
		suf[i] = max<ll>(pos[i], suf[i+1] - S * T);

	ll pk = pos[k];

	if (k == 1) return (suf[k] - pk) <= S * T;
	if (k == n) return (pk - pf[k]) <= S * T;

	ll da = max(0ll, suf[k] - pk), db = max(0ll, pk - pf[k]);

	return min(da, db) * 2 + max(da, db) <= 2 * S * T;

}

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k >> T;
	for (int i = 1;i <= n;++i)
		cin >> pos[i];

	if (n <= 1) return puts("0"), 0;

	ll L = 1, R = pos[n], M;

	while (L < R) {
		M = L + R >> 1;
		if (valid(M))
			R = M;
		else L = M + 1;
	}

	cout << L << '\n';
	
}

Compilation message

sparklers.cpp: In function 'int32_t main()':
sparklers.cpp:63:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   63 |   M = L + R >> 1;
      |       ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -