Submission #405109

# Submission time Handle Problem Language Result Execution time Memory
405109 2021-05-15T17:49:13 Z rainboy Shortcut (IOI16_shortcut) C
0 / 100
1 ms 204 KB
#include "shortcut_c.h"

#define N	1000000
#define INF	0x3f3f3f3f3f3f3f3f

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

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

long long *aa;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] < aa[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

long long find_shortcut(int n, int *xx_, int *dd, int c) {
	static long long xx[N], yy[N], zz[N];
	static int kk[N], ll[N];
	int h1, h2, i, j, j1, j2, k, l, d, d1, d2, can;
	long long x, y, y_, z, z_, lower, upper;

	for (i = 1; i < n; i++)
		xx[i] = xx[i - 1] + xx_[i - 1];
	d1 = d2 = 0;
	for (i = 0; i < n; i++) {
		d = dd[i], x = xx[i], yy[i] = d - x, zz[i] = d + x;
		if (d1 < d)
			d2 = d1, d1 = d;
		else if (d2 < d)
			d2 = d;
		kk[i] = ll[i] = i;
	}
	aa = yy, sort(kk, 0, n);
	aa = zz, sort(ll, 0, n);
	lower = d1 + d2 - 1, upper = xx[n - 1] + d1 + d2;
	while (upper - lower > 1) {
		long long d = (lower + upper) / 2, p, q, r, s;

		p = q = r = s = INF, y_ = -INF;
		for (h1 = 0, h2 = n - 1; h1 < n; h1++) {
			k = kk[h1], y = yy[k], z = zz[k];
			while (h2 >= 0 && y + zz[ll[h2]] > d)
				y_ = max(y_, yy[ll[h2--]]);
			if (h2 + 1 == n)
				continue;
			l = ll[h2 + 1], z_ = zz[l];
			p = min(p, -(z + z_)), q = min(q, -(z + y_)), r = min(r, -(y + z_)), s = min(s, -(y + y_));
		}
		if (p != INF)
			p += d - c;
		if (q != INF)
			q += d - c;
		if (r != INF)
			r += d - c;
		if (s != INF)
			s += d - c;
		can = 0;
		for (i = 0, j1 = -1, j2 = n - 1; i < n; i++) {
			x = xx[i];
			while (j1 + 1 < n && - x + xx[j1 + 1] <= q)
				j1++;
			while (j2 >= 0 && + x + xx[j2] > s)
				j2--;
			j = min(j1, j2);
			if (i < j && - x - xx[j] <= p && + x - xx[j] <= r) {
				can = 1;
				break;
			}
		}
		if (can)
			upper = d;
		else
			lower = d;
	}
	return upper;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 204 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -