답안 #684195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684195 2023-01-20T15:58:19 Z rainboy Dragon 2 (JOI17_dragon2) C
100 / 100
3756 ms 3968 KB
#include <stdio.h>
#include <stdlib.h>

#define N	30000

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

int inside(int x1, int y1, int x2, int y2, int x3, int y3) {
	int tmp;

	if (cross(x1, y1, x2, y2) > 0)
		tmp = x1, x1 = x2, x2 = tmp, tmp = y1, y1 = y2, y2 = tmp;
	return cross(x1, y1, x3, y3) < 0 && cross(x3, y3, x2, y2) < 0;
}

int *ei[N], eo[N];

void append(int c, int i) {
	int o = eo[c]++;

	if (o >= 2 && (o & o - 1) == 0)
		ei[c] = (int *) realloc(ei[c], o * 2 * sizeof *ei[c]);
	ei[c][o] = i;
}

int main() {
	static int xx[N], yy[N];
	int n, m, q, i, j, c, x1, y1, x2, y2;

	scanf("%d%d", &n, &m);
	for (c = 0; c < m; c++)
		ei[c] = (int *) malloc(2 * sizeof *ei[c]);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &xx[i], &yy[i], &c), c--;
		append(c, i);
	}
	scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &q);
	while (q--) {
		int a, b, ans, o, o_;

		scanf("%d%d", &a, &b), a--, b--;
		ans = 0;
		for (o = eo[a]; o--; ) {
			i = ei[a][o];
			for (o_ = eo[b]; o_--; ) {
				j = ei[b][o_];
				if (inside(x1 - xx[i], y1 - yy[i], x2 - xx[i], y2 - yy[i], xx[j] - xx[i], yy[j] - yy[i]))
					ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

dragon2.c: In function 'append':
dragon2.c:23:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   23 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
dragon2.c: In function 'main':
dragon2.c:32:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
dragon2.c:36:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   scanf("%d%d%d", &xx[i], &yy[i], &c), c--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragon2.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d%d", &a, &b), a--, b--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 340 KB Output is correct
2 Correct 20 ms 468 KB Output is correct
3 Correct 27 ms 476 KB Output is correct
4 Correct 40 ms 1308 KB Output is correct
5 Correct 36 ms 1556 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 7 ms 312 KB Output is correct
9 Correct 6 ms 304 KB Output is correct
10 Correct 7 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1122 ms 1396 KB Output is correct
2 Correct 2025 ms 1392 KB Output is correct
3 Correct 55 ms 1580 KB Output is correct
4 Correct 15 ms 1436 KB Output is correct
5 Correct 12 ms 2600 KB Output is correct
6 Correct 1072 ms 1372 KB Output is correct
7 Correct 1081 ms 1380 KB Output is correct
8 Correct 515 ms 1364 KB Output is correct
9 Correct 494 ms 1128 KB Output is correct
10 Correct 600 ms 1164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 340 KB Output is correct
2 Correct 20 ms 468 KB Output is correct
3 Correct 27 ms 476 KB Output is correct
4 Correct 40 ms 1308 KB Output is correct
5 Correct 36 ms 1556 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 7 ms 312 KB Output is correct
9 Correct 6 ms 304 KB Output is correct
10 Correct 7 ms 356 KB Output is correct
11 Correct 1122 ms 1396 KB Output is correct
12 Correct 2025 ms 1392 KB Output is correct
13 Correct 55 ms 1580 KB Output is correct
14 Correct 15 ms 1436 KB Output is correct
15 Correct 12 ms 2600 KB Output is correct
16 Correct 1072 ms 1372 KB Output is correct
17 Correct 1081 ms 1380 KB Output is correct
18 Correct 515 ms 1364 KB Output is correct
19 Correct 494 ms 1128 KB Output is correct
20 Correct 600 ms 1164 KB Output is correct
21 Correct 1094 ms 1364 KB Output is correct
22 Correct 2036 ms 1372 KB Output is correct
23 Correct 2336 ms 1524 KB Output is correct
24 Correct 670 ms 2660 KB Output is correct
25 Correct 64 ms 2932 KB Output is correct
26 Correct 68 ms 3840 KB Output is correct
27 Correct 17 ms 2764 KB Output is correct
28 Correct 17 ms 2772 KB Output is correct
29 Correct 3756 ms 3704 KB Output is correct
30 Correct 88 ms 3644 KB Output is correct
31 Correct 42 ms 3808 KB Output is correct
32 Correct 71 ms 3788 KB Output is correct
33 Correct 601 ms 3772 KB Output is correct
34 Correct 42 ms 3968 KB Output is correct
35 Correct 42 ms 3660 KB Output is correct
36 Correct 45 ms 3596 KB Output is correct
37 Correct 43 ms 3872 KB Output is correct
38 Correct 976 ms 3812 KB Output is correct
39 Correct 797 ms 3812 KB Output is correct
40 Correct 643 ms 3848 KB Output is correct
41 Correct 2796 ms 3932 KB Output is correct
42 Correct 1808 ms 3860 KB Output is correct
43 Correct 1423 ms 3800 KB Output is correct
44 Correct 2295 ms 2216 KB Output is correct
45 Correct 1147 ms 2112 KB Output is correct
46 Correct 748 ms 2352 KB Output is correct
47 Correct 1139 ms 2112 KB Output is correct
48 Correct 683 ms 2104 KB Output is correct
49 Correct 434 ms 2100 KB Output is correct