답안 #684842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684842 2023-01-22T16:05:14 Z rainboy Long Distance Coach (JOI17_coach) C
71 / 100
2000 ms 7748 KB
#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

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]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 6 ms 340 KB Output is correct
39 Correct 7 ms 340 KB Output is correct
40 Correct 6 ms 404 KB Output is correct
41 Correct 8 ms 340 KB Output is correct
42 Correct 6 ms 340 KB Output is correct
43 Correct 5 ms 340 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 5 ms 340 KB Output is correct
46 Correct 5 ms 340 KB Output is correct
47 Correct 5 ms 412 KB Output is correct
48 Correct 6 ms 340 KB Output is correct
49 Correct 6 ms 340 KB Output is correct
50 Correct 6 ms 408 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 6 ms 340 KB Output is correct
39 Correct 7 ms 340 KB Output is correct
40 Correct 6 ms 404 KB Output is correct
41 Correct 8 ms 340 KB Output is correct
42 Correct 6 ms 340 KB Output is correct
43 Correct 5 ms 340 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 5 ms 340 KB Output is correct
46 Correct 5 ms 340 KB Output is correct
47 Correct 5 ms 412 KB Output is correct
48 Correct 6 ms 340 KB Output is correct
49 Correct 6 ms 340 KB Output is correct
50 Correct 6 ms 408 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
52 Execution timed out 2080 ms 7748 KB Time limit exceeded
53 Halted 0 ms 0 KB -