Submission #59853

# Submission time Handle Problem Language Result Execution time Memory
59853 2018-07-23T08:09:42 Z 윤교준(#1726) Sparklers (JOI17_sparklers) C++11
0 / 100
2000 ms 416 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 100005;

int A[MAXN];

int N, K, T, P;

ll f(int P, int i) { return ll(A[i]) - 2ll * P * T * i; }
ll g(int P, int i) { return -f(P, i); }
ll g(int i) { return g(P, i); }

bool isp(int P) {
	::P = P;
	if(g(1) > g(N)) return false;

	int pl = K, pr = K, l = K, r = K;
	for(int i = 1; i <= K; i++) if(g(i) < g(pl)) pl = i;
	for(int i = K; i <= N; i++) if(g(pr) <= g(i)) pr = i;

	for(;;) {
		bool flag = false;
		int i = l;
		for(; pl < i;) {
			if(g(i-1) <= g(r)) i--;
			if(g(i) <= g(l)) break;
		}
		if(i < l && g(i) <= g(l)) {
			flag = true;
			l = i;
		}
		for(i = r; i < pr;) {
			if(g(l) <= g(i+1)) i++;
			if(g(r) <= g(i)) break;
		}
		if(r < i && g(r) <= g(i)) {
			flag = true;
			r = i;
		}
		if(!flag) break;
	}
	
	if(l != pl || r != pr) return false;

	l = 1; r = N;
	for(;;) {
		bool flag = false;
		int i = l;
		for(; i < pl;) {
			if(g(i+1) <= g(r)) i++;
			if(g(i) <= g(l)) break;
		}
		if(l < i && g(i) <= g(l)) {
			flag = true;
			l = i;
		}
		for(i = r; pr < i;) {
			if(g(l) <= g(i-1)) i--;
			if(g(r) <= g(i)) break;
		}
		if(i < r && g(r) <= g(i)) {
			flag = true;
			r = i;
		}
		if(!flag) break;
	}

	return l == pl && r == pr;
}

int getAns() {
	int s = 0, e = INF/T+2; for(int m; s < e;) {
		m = (s+e) >> 1;
		if(isp(m)) e = m;
		else s = m+1;
	}
	return s;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> K >> T;
	for(int i = 1; i <= N; i++) cin >> A[i];

	cout << getAns() << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Execution timed out 2061 ms 416 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Execution timed out 2061 ms 416 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Execution timed out 2061 ms 416 KB Time limit exceeded
4 Halted 0 ms 0 KB -