답안 #636572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636572 2022-08-29T15:10:26 Z rainboy Sightseeing in Kyoto (JOI22_kyoto) C
100 / 100
33 ms 3124 KB
#include <stdio.h>

#define N	100000
#define M	100000
#define INF	0x3f3f3f3f3f3f3f3f

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];
	int n, m, i, j, cnt;
	long long ans;

	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]);
	cnt = 0;
	for (i = 0; i < n; i++) {
		while (cnt >= 2 && cross(ii[cnt - 2], aa[ii[cnt - 2]], ii[cnt - 1], aa[ii[cnt - 1]], i, aa[i]) <= 0)
			cnt--;
		ii[cnt++] = i;
	}
	n = cnt;
	cnt = 0;
	for (j = 0; j < m; j++) {
		while (cnt >= 2 && cross(jj[cnt - 2], bb[jj[cnt - 2]], jj[cnt - 1], bb[jj[cnt - 1]], j, bb[j]) <= 0)
			cnt--;
		jj[cnt++] = j;
	}
	m = cnt;
	i = 0, j = 0, ans = 0;
	while (i + 1 < n || j + 1 < m)
		if (j + 1 == m || i + 1 < n && cross2(ii[i + 1] - ii[i], aa[ii[i + 1]] - aa[ii[i]], jj[j + 1] - jj[j], bb[jj[j + 1]] - bb[jj[j]]) >= 0)
			ans += (long long) bb[jj[j]] * (ii[i + 1] - ii[i]), i++;
		else
			ans += (long long) aa[ii[i]] * (jj[j + 1] - jj[j]), j++;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

kyoto.c: In function 'main':
kyoto.c:41:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   41 |   if (j + 1 == m || i + 1 < n && cross2(ii[i + 1] - ii[i], aa[ii[i + 1]] - aa[ii[i]], jj[j + 1] - jj[j], bb[jj[j + 1]] - bb[jj[j]]) >= 0)
      |                     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kyoto.c:20:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
kyoto.c:22:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
kyoto.c:24:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d", &bb[j]);
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 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 1 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
# 결과 실행 시간 메모리 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 8 ms 516 KB Output is correct
5 Correct 7 ms 596 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 19 ms 980 KB Output is correct
8 Correct 21 ms 980 KB Output is correct
9 Correct 20 ms 1040 KB Output is correct
10 Correct 20 ms 968 KB Output is correct
11 Correct 21 ms 952 KB Output is correct
12 Correct 25 ms 976 KB Output is correct
13 Correct 20 ms 980 KB Output is correct
14 Correct 23 ms 1132 KB Output is correct
15 Correct 19 ms 980 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 1 ms 212 KB Output is correct
22 Correct 1 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
# 결과 실행 시간 메모리 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 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 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 1 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 8 ms 516 KB Output is correct
33 Correct 7 ms 596 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 19 ms 980 KB Output is correct
36 Correct 21 ms 980 KB Output is correct
37 Correct 20 ms 1040 KB Output is correct
38 Correct 20 ms 968 KB Output is correct
39 Correct 21 ms 952 KB Output is correct
40 Correct 25 ms 976 KB Output is correct
41 Correct 20 ms 980 KB Output is correct
42 Correct 23 ms 1132 KB Output is correct
43 Correct 19 ms 980 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 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 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 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 16 ms 612 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 5 ms 340 KB Output is correct
59 Correct 29 ms 940 KB Output is correct
60 Correct 29 ms 1028 KB Output is correct
61 Correct 28 ms 980 KB Output is correct
62 Correct 29 ms 1100 KB Output is correct
63 Correct 33 ms 1352 KB Output is correct
64 Correct 29 ms 2944 KB Output is correct
65 Correct 29 ms 2984 KB Output is correct
66 Correct 27 ms 2912 KB Output is correct
67 Correct 27 ms 3124 KB Output is correct