Submission #684842

#TimeUsernameProblemLanguageResultExecution timeMemory
684842rainboyLong Distance Coach (JOI17_coach)C11
71 / 100
2080 ms7748 KiB
#include <stdio.h>

#define N	200001
#define M	200001
#define INF	0x3f3f3f3f3f3f3f3fLL

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

unsigned int X = 12345;

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

long long yy[N]; int cc[N], n;
long long xx[M]; int m;
long long l, t;

long long *vv;

int compare(int i, int j) {
	long long ri = vv[i] % t, rj = vv[j] % t;

	return ri == rj ? 0 : (ri < rj ? -1 : 1);
}

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) {
			int c = compare(ii[j], i_);

			if (c == 0)
				j++;
			else if (c < 0) {
				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;
	}
}

int main() {
	static int hh[M], ii[N];
	static long long aa[N], dp[N];
	int w, h, h_, i, j;
	long long z, ans;

	scanf("%lld%d%d%d%lld", &l, &m, &n, &w, &t), m++, n++;
	xx[0] = l;
	for (h = 1; h < m; h++)
		scanf("%lld", &xx[h]);
	for (h = 0; h < m; h++)
		hh[h] = h;
	vv = xx, sort(hh, 0, m);
	yy[0] = 0, cc[0] = 0;
	for (i = 1; i < n; i++)
		scanf("%lld%d", &yy[i], &cc[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	vv = yy, sort(ii, 0, n);
	for (i = 0; i < n; i++)
		aa[i] = (l - yy[ii[i]]) / t + 1;
	for (j = 0, h = 0; j < n; j++) {
		while (h < m && xx[hh[h]] % t < yy[ii[j]]) {
			h_ = hh[h++];
			for (i = j - 1; i >= 0; i--)
				aa[i] = min(aa[i], xx[h_] / t);
		}
		if (j == 0)
			dp[j] = 0;
		else {
			dp[j] = INF;
			z = 0;
			for (i = j - 1; i >= 0; i--) {
				dp[j] = min(dp[j], dp[i] + z);
				z += aa[i] * w;
			}
		}
		dp[j] += aa[j] * w - cc[ii[j]];
	}
	while (h < m) {
		h_ = hh[h++];
		for (i = j - 1; i >= 0; i--)
			aa[i] = min(aa[i], xx[h_] / t);
	}
	ans = INF, z = 0;
	for (i = n - 1; i >= 0; i--) {
		ans = min(ans, dp[i] + z);
		z += aa[i] * w;
	}
	for (i = 0; i < n; i++)
		ans += cc[i];
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

coach.c: In function 'main':
coach.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%lld%d%d%d%lld", &l, &m, &n, &w, &t), m++, n++;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%lld", &xx[h]);
      |   ^~~~~~~~~~~~~~~~~~~~~
coach.c:64:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%lld%d", &yy[i], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...