Submission #636566

# Submission time Handle Problem Language Result Execution time Memory
636566 2022-08-29T14:56:48 Z rainboy Sightseeing in Kyoto (JOI22_kyoto) C
40 / 100
123 ms 146636 KB
#include <stdio.h>
#include <string.h>

#define N	100000
#define M	100000
#define N_	3000
#define M_	3000
#define INF	0x3f3f3f3f3f3f3f3f

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

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

long long cross(int x0, int y0, int x1, int y1, int x2, int y2) {
	return cross2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}

int main() {
	static int aa[N], bb[M], ii[N_], jj[M_];
	static long long dp[N_][M_];
	int n, n_, m, m_, i, j;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &bb[j]);
	n_ = 0;
	for (i = 0; i < n; i++) {
		while (n_ >= 2 && cross(ii[n_ - 2], aa[ii[n_ - 2]], ii[n_ - 1], aa[ii[n_ - 1]], i, aa[i]) <= 0)
			n_--;
		ii[n_++] = i;
	}
	m_ = 0;
	for (j = 0; j < m; j++) {
		while (m_ >= 2 && cross(jj[m_ - 2], bb[jj[m_ - 2]], jj[m_ - 1], bb[jj[m_ - 1]], j, bb[j]) <= 0)
			m_--;
		jj[m_++] = j;
	}
	for (i = 0; i < n_; i++)
		memset(dp[i], 0x3f, m_ * sizeof *dp[i]);
	dp[0][0] = 0;
	for (i = 0; i < n_; i++)
		for (j = 0; j < m_; j++) {
			long long x = dp[i][j];

			if (x == INF)
				continue;
			if (j + 1 < m_)
				dp[i][j + 1] = min(dp[i][j + 1], x + (long long) aa[ii[i]] * (jj[j + 1] - jj[j]));
			if (i + 1 < n_)
				dp[i + 1][j] = min(dp[i + 1][j], x + (long long) bb[jj[j]] * (ii[i + 1] - ii[i]));
		}
	printf("%lld\n", dp[n_ - 1][m_ - 1]);
	return 0;
}

Compilation message

kyoto.c: In function 'main':
kyoto.c:25:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
kyoto.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
kyoto.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d", &bb[j]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 9 ms 12116 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 9 ms 1072 KB Output is correct
5 Correct 8 ms 1236 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 21 ms 1832 KB Output is correct
8 Correct 23 ms 1828 KB Output is correct
9 Correct 22 ms 1984 KB Output is correct
10 Correct 20 ms 2052 KB Output is correct
11 Correct 20 ms 5236 KB Output is correct
12 Correct 25 ms 1868 KB Output is correct
13 Correct 20 ms 1904 KB Output is correct
14 Correct 22 ms 1804 KB Output is correct
15 Correct 25 ms 1976 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 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 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 292 KB Output is correct
23 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 9 ms 12116 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 596 KB Output is correct
32 Correct 9 ms 1072 KB Output is correct
33 Correct 8 ms 1236 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 21 ms 1832 KB Output is correct
36 Correct 23 ms 1828 KB Output is correct
37 Correct 22 ms 1984 KB Output is correct
38 Correct 20 ms 2052 KB Output is correct
39 Correct 20 ms 5236 KB Output is correct
40 Correct 25 ms 1868 KB Output is correct
41 Correct 20 ms 1904 KB Output is correct
42 Correct 22 ms 1804 KB Output is correct
43 Correct 25 ms 1976 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 292 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 14 ms 1572 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 2 ms 564 KB Output is correct
58 Correct 4 ms 852 KB Output is correct
59 Correct 28 ms 3004 KB Output is correct
60 Correct 36 ms 3008 KB Output is correct
61 Correct 28 ms 3260 KB Output is correct
62 Correct 28 ms 3276 KB Output is correct
63 Runtime error 123 ms 146636 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -