답안 #683948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683948 2023-01-19T18:12:31 Z rainboy Long Distance Coach (JOI17_coach) C
0 / 100
1 ms 340 KB
#include <stdio.h>

#define N	200000
#define M	200002
#define INF	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; }

int main() {
	static int cc[N];
	static long long rr[N], xx[M + 2];
	int n, m, c, b, b_, i, j;
	long long md, t, t1, t2, x_, ans, z;

	scanf("%lld%d%d%d%lld", &x_, &m, &n, &c, &md), m += 2;
	xx[0] = -1, xx[m - 1] = x_;
	for (j = 1; j + 1 < m; j++)
		scanf("%lld", &xx[j]);
	rr[0] = 0;
	for (i = 0; i < n; i++)
		scanf("%lld%d", &rr[i], &cc[i]);
	ans = INF;
	for (b = 0; b < 1 << n; b++) {
		z = 0;
		for (i = 0; i < n; i++)
			if ((b & 1 << i) == 0)
				z += cc[i];
		b_ = 0;
		for (j = 1; j < m; j++) {
			t = max(xx[j - 1] + 1, (xx[j] + md) / md * md - md);
			for (i = 0; i < n; i++)
				if ((b & 1 << i) != 0)
					t = max(t, (xx[j] + md - rr[i]) / md * md - (md - rr[i]));
			t1 = (xx[j - 1] + md) / md * md - md;
			t2 = (xx[j] + md) / md * md - md;
			z += ((t2 - t1) / md) * c;
			for (i = 0; i < n; i++)
				if ((b_ & 1 << i) == 0) {
					t1 = (xx[j - 1] + (md - rr[i])) / md * md - (md - rr[i]);
					t2 = (xx[j] + (md - rr[i])) / md * md - (md - rr[i]);
					if (t1 < t2) {
						z += ((min(t, t2) - t1) / md) * c;
						if (t2 > t)
							b_ |= 1 << i;
					}
				}
		}
		ans = min(ans, z);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

coach.c: In function 'main':
coach.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%lld%d%d%d%lld", &x_, &m, &n, &c, &md), m += 2;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%lld", &xx[j]);
      |   ^~~~~~~~~~~~~~~~~~~~~
coach.c:22:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%lld%d", &rr[i], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 292 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 292 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 292 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 1 ms 292 KB Output isn't correct
6 Halted 0 ms 0 KB -