답안 #683964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683964 2023-01-19T19:31:22 Z rainboy Long Distance Coach (JOI17_coach) C
71 / 100
2000 ms 16708 KB
#include <stdio.h>

#define N	200002
#define M	200002
#define LINF	0x3f3f3f3f3f3f3f3fLL

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 xx[M], xx_[M]; int ll[M], rr[M], jj[M], m;

int compare_x(int i, int j) {
	return xx[i] == xx[j] ? 0 : (xx[i] < xx[j] ? -1 : 1);
}

long long uu[N]; int cc[N], ii[N], n;

int compare_u(int i, int j) {
	return uu[i] == uu[j] ? 0 : (uu[i] < uu[j] ? -1 : 1);
}

int compare_r(int i, int j) {
	return rr[i] - rr[j];
}

int (*compare)(int, int);

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 search(long long u) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int i = (lower + upper) / 2;

		if (uu[ii[i]] <= u)
			lower = i;
		else
			upper = i;
	}
	return lower;
}

int main() {
	static long long tt[N], dp[N];
	int i, i_, j, j_;
	long long md, w, x_, x, y, z, ans;

	scanf("%lld%d%d%lld%lld", &x_, &m, &n, &w, &md), n++, m += 2;
	xx[0] = -1, xx[m - 1] = x_;
	for (j = 1; j + 1 < m; j++)
		scanf("%lld", &xx[j]);
	for (j = 0; j < m; j++)
		jj[j] = j;
	compare = compare_x, sort(jj, 0, m);
	for (j = 0; j < m; j++)
		xx_[j] = xx[jj[j]];
	for (j = 0; j < m; j++)
		xx[j] = xx_[j];
	uu[0] = 0;
	for (i = 1; i < n; i++)
		scanf("%lld%d", &uu[i], &cc[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	compare = compare_u, sort(ii, 0, n);
	dp[0] = 0;
	for (j = 1; j < m; j++) {
		x = xx[j - 1], y = xx[j];
		ll[j] = search(y % md - (y - x)) + 1, rr[j] = search(y % md);
	}
	for (j = 1; j < m; j++)
		jj[j - 1] = j;
	compare = compare_r, sort(jj, 0, m - 1);
	for (i = 0; i < n; i++)
		tt[i] = (x_ + md - uu[ii[i]]) / md;
	for (i = 0, j = 0; i < n; i++) {
		if (i == 0)
			dp[i] = ((x_ + md - uu[ii[i]]) / md) * w;
		else {
			dp[i] = LINF, z = 0;
			for (i_ = i - 1; i_ >= 0; i_--) {
				dp[i] = min(dp[i], dp[i_] + z);
				z += tt[i_] * w + cc[ii[i_]];
			}
			dp[i] += ((x_ + md - uu[ii[i]]) / md) * w;
		}
		while (j < m - 1 && rr[j_ = jj[j]] == i) {
			j++;
			for (i_ = ll[j_]; i_ <= rr[j_]; i_++)
				tt[i_] = min(tt[i_], (xx[j_] + md - uu[ii[i_]]) / md - 1);
		}
	}
	ans = LINF, z = 0;
	for (i_ = n - 1; i_ >= 0; i_--) {
		ans = min(ans, dp[i_] + z);
		z += tt[i_] * w + cc[ii[i_]];
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

coach.c: In function 'main':
coach.c:75:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  scanf("%lld%d%d%lld%lld", &x_, &m, &n, &w, &md), n++, m += 2;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.c:78:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   scanf("%lld", &xx[j]);
      |   ^~~~~~~~~~~~~~~~~~~~~
coach.c:88:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%lld%d", &uu[i], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 300 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 300 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 17 ms 500 KB Output is correct
39 Correct 16 ms 504 KB Output is correct
40 Correct 23 ms 468 KB Output is correct
41 Correct 16 ms 500 KB Output is correct
42 Correct 17 ms 492 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 23 ms 496 KB Output is correct
45 Correct 20 ms 468 KB Output is correct
46 Correct 18 ms 480 KB Output is correct
47 Correct 19 ms 500 KB Output is correct
48 Correct 21 ms 536 KB Output is correct
49 Correct 6 ms 464 KB Output is correct
50 Correct 17 ms 500 KB Output is correct
51 Correct 15 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 300 KB Output is correct
33 Correct 0 ms 292 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 17 ms 500 KB Output is correct
39 Correct 16 ms 504 KB Output is correct
40 Correct 23 ms 468 KB Output is correct
41 Correct 16 ms 500 KB Output is correct
42 Correct 17 ms 492 KB Output is correct
43 Correct 15 ms 468 KB Output is correct
44 Correct 23 ms 496 KB Output is correct
45 Correct 20 ms 468 KB Output is correct
46 Correct 18 ms 480 KB Output is correct
47 Correct 19 ms 500 KB Output is correct
48 Correct 21 ms 536 KB Output is correct
49 Correct 6 ms 464 KB Output is correct
50 Correct 17 ms 500 KB Output is correct
51 Correct 15 ms 496 KB Output is correct
52 Execution timed out 2055 ms 16708 KB Time limit exceeded
53 Halted 0 ms 0 KB -