Submission #527889

# Submission time Handle Problem Language Result Execution time Memory
527889 2022-02-18T16:08:52 Z rainboy 코알라 (JOI13_koala) C
50 / 100
32 ms 1812 KB
#include <stdio.h>

#define N	100000
#define SMALL	1010
#define D	100
#define INF	0x3f3f3f3f3f3f3f3fLL

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

int main() {
	static int xx[N + 2], bb[N + 2];
	static long long dp[N + 2], dq[D];
	int n, xl, xr, d, a, i, j, r;

	scanf("%d%d%d%d%d", &xl, &xr, &d, &a, &n);
	xx[0] = xl;
	for (i = 1; i <= n; i++)
		scanf("%d%d", &xx[i], &bb[i]);
	xx[n + 1] = xr;
	n += 2;
	if (n <= SMALL) {
		dp[0] = 0;
		for (j = 1; j < n; j++) {
			dp[j] = -INF;
			for (i = 0; i < j; i++)
				dp[j] = max(dp[j], dp[i] - (long long) (xx[j] - xx[i] + d - 1) / d * a + bb[j]);
		}
	} else if (d <= D) {
		for (r = 0; r < d; r++)
			dq[r] = -INF;
		for (j = 0; j < n; j++) {
			if (j == 0)
				dp[j] = 0;
			else {
				dp[j] = -INF;
				for (r = 0; r < d; r++)
					dp[j] = max(dp[j], dq[r] - (r < xx[j] % d ? a : 0));
				dp[j] += bb[j];
			}
			dq[xx[j] % d] = max(dq[xx[j] % d], dp[j]);
		}
		dp[n - 1] -= (long long) (xx[n - 1] / d - xx[0] / d) * a;
	} else {
		printf(":(\n");
		return 0;
	}
	printf("%lld\n", dp[n - 1]);
	return 0;
}

Compilation message

koala.c: In function 'main':
koala.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d%d%d%d%d", &xl, &xr, &d, &a, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d%d", &xx[i], &bb[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 4 ms 204 KB Output is correct
6 Correct 3 ms 304 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 5 ms 204 KB Output is correct
9 Correct 3 ms 204 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1752 KB Output is correct
2 Correct 28 ms 1792 KB Output is correct
3 Correct 13 ms 1240 KB Output is correct
4 Correct 27 ms 1784 KB Output is correct
5 Correct 21 ms 1200 KB Output is correct
6 Correct 9 ms 844 KB Output is correct
7 Correct 25 ms 1812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -