제출 #683121

#제출 시각아이디문제언어결과실행 시간메모리
683121rainboySparklers (JOI17_sparklers)C11
100 / 100
51 ms5528 KiB
#include <stdio.h>

#define N	100000
#define N2	(N * 2 + 1)
#define N4	(N2 * 2)
#define INF	0x3f3f3f3f

long long min(long long a, long long b) { return a < b ? a : b; }

int solve(int *xx, int n, int s, int x) {
	static long long aa[N2], bb[N2], aa_[N4], bb_[N4];
	int na, nb, na_, nb_, r, i, ia, ib, j;
	long long a, b, tmp;

	na = 0;
	aa[na++] = x;
	for (i = s; i > 0; i--)
		aa[na++] = -(xx[i] - xx[i - 1]), aa[na++] = x;
	for (i = 1; i < na; i++)
		aa[i] += aa[i - 1];
	nb = 0;
	bb[nb++] = 0;
	for (i = s; i + 1 < n; i++)
		bb[nb++] = -(xx[i + 1] - xx[i]), bb[nb++] = x;
	for (i = 1; i < nb; i++)
		bb[i] += bb[i - 1];
	for (r = 0; r < 2; r++) {
		i = 0, na_ = 0;
		while (1) {
			aa_[na_++] = aa[i];
			j = i + 1, a = aa[i];
			while (j < na && (r == 0 ? aa[j] <= aa[i] : aa[j] < aa[i]))
				a = min(a, aa[j++]);
			if (j == na)
				break;
			aa_[na_++] = a;
			i = j;
		}
		i = 0, nb_ = 0;
		while (1) {
			bb_[nb_++] = bb[i];
			j = i + 1, b = bb[i];
			while (j < nb && (r == 0 ? bb[j] <= bb[i] : bb[j] < bb[i]))
				b = min(b, bb[j++]);
			if (j == nb)
				break;
			bb_[nb_++] = b;
			i = j;
		}
		if (aa_[0] + bb_[0] < 0)
			return 0;
		ia = ib = 0;
		while (ia + 2 < na_ || ib + 2 < nb_)
			if (ia + 2 < na_ && aa_[ia + 1] + bb_[ib] >= 0)
				ia += 2;
			else if (ib + 2 < nb_ && aa_[ia] + bb_[ib + 1] >= 0)
				ib += 2;
			else
				return 0;
		for (i = 0, j = na - 1; i < j; i++, j--)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
		for (i = 0, j = nb - 1; i < j; i++, j--)
			tmp = bb[i], bb[i] = bb[j], bb[j] = tmp;
	}
	return 1;
}

int main() {
	static int xx[N];
	int n, s, t, i, lower, upper;

	scanf("%d%d%d", &n, &s, &t), s--;
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	lower = -1, upper = INF;
	while (upper - lower > 1) {
		int v = (lower + upper) / 2;

		if (solve(xx, n, s, min((long long) t * v * 2, INF)))
			upper = v;
		else
			lower = v;
	}
	printf("%d\n", upper);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sparklers.c: In function 'main':
sparklers.c:72:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |  scanf("%d%d%d", &n, &s, &t), s--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.c:74:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...