답안 #157605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157605 2019-10-12T15:05:33 Z imyujin Sparklers (JOI17_sparklers) C++17
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

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

#define fi first
#define se second

const int MAXN = 100010;
const int INF = 1e9 + 5;

lint X[MAXN];

lint solve(vector<lint> &v, vector<pll> &r) {
	lint x = 0;
	for(auto &a : v) {
		pll t = pll(a, max(-a, 0ll));
		while(!r.empty() && t.fi < 0) {
			t.se = r.back().se - t.fi;
			t.fi += r.back().fi;
			r.pop_back();
		}
		if(t.fi >= 0) r.push_back(t);
		else x += t.se;
	}
	return x;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, K;
	lint T;

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

	lint s = 0, e = INF;
	while(s < e) {
		lint m = (s + e) / 2;
		vector<lint> v1, v2;
		for(int i = 1; i < K; i++) v1.push_back(2 * T * m - X[i + 1] + X[i]);
		for(int i = N; i > K; i--) v2.push_back(2 * T * m - X[i] + X[i - 1]);
		lint sum = 0;
		for(auto a : v1) sum += a;
		for(auto a : v2) sum += a;
		//printf("m = %lld\n", m);
		if(sum < 0) {
			s = m + 1;
			continue;
		}
		vector<pll> r1, r2;
		lint x1 = solve(v1, r1);
		lint x2 = solve(v2, r2);
		/*
		printf("v1 : ");
		for(auto a : v1) printf("%lld ", a);
		printf("\nv2 : ");
		for(auto a : v2) printf("%lld ", a);
		printf("\nr1 : ");
		for(auto a : r1) printf("(%lld, %lld) ", a.fi, a.se);
		printf("\nr2 : ");
		for(auto a : r2) printf("(%lld, %lld) ", a.fi, a.se);
		printf("\n");
		*/
		lint t = 0;
		int p1 = int(r1.size()) - 1, p2 = int(r2.size()) - 1;
		while(p1 >= 0 || p2 >= 0) {
			if(p2 < 0 || (p1 >= 0 && r1[p1].se < r2[p2].se)) {
				if(t < r1[p1].se) break;
				t += r1[p1--].fi;
			}
			else {
				if(t < r2[p2].se) break;
				t += r2[p2--].fi;
			}
		}
		if(p1 >= 0 || p2 >= 0 || t - x1 - x2 < 0) s = m + 1;
		else e = m;
	}
	cout << s << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -