Submission #624850

# Submission time Handle Problem Language Result Execution time Memory
624850 2022-08-08T21:08:16 Z dutinmeow Dragon 2 (JOI17_dragon2) C++17
100 / 100
2794 ms 3968 KB
#include <bits/stdc++.h>
using namespace std;

struct point {
	long long x, y;

	point() : x(0), y(0) {}

	point(long long _x, long long _y) : x(_x), y(_y) {}

	point &operator+=(const point &rhs) { 
		x += rhs.x;
		y += rhs.y;
		return *this;
	}

	point &operator-=(const point &rhs) { 
		x -= rhs.x;
		y -= rhs.y;
		return *this;
	}
};

point make_point(long long x, long long y) { return point(x, y); }

point operator+(point lhs, const point &rhs) { return lhs += rhs; }

point operator-(point lhs, const point &rhs) { return lhs -= rhs; }

int operator^(const point &lhs, const point &rhs) { return lhs.x * rhs.y - lhs.y * rhs.x; }

bool ccw(const point &a, const point &b, const point &c) { 
	// return ((c - a) ^ (b - a)) < 0; 
	return (c.x - a.x) * (b.y - a.y) < (c.y - a.y) * (b.x - a.x);
}

bool ccw(const point &b, const point &c) { return ccw(point(), b, c); }

bool cpt(const point &a, const point &b, const point &c) {
	if (ccw(b, c))
		return ccw(b, a) && ccw(a, c);
	else 
		return ccw(a, b) && ccw(c, a);
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<point>> cat(M);
	for (int i = 0; i < N; i++) {
		long long x, y;
		int c;
		cin >> x >> y >> c;
		cat[c - 1].emplace_back(x, y);
	}

	long long sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	point S(sx, sy), T(tx, ty);

	int Q;
	cin >> Q;
	while (Q--) {
		int c1, c2;
		cin >> c1 >> c2;
		c1--, c2--;
		long long ans = 0;
		for (const point &p : cat[c1])
			for (const point &q : cat[c2])
				ans += int(cpt(q - p, S - p, T - p));
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 340 KB Output is correct
2 Correct 21 ms 468 KB Output is correct
3 Correct 32 ms 500 KB Output is correct
4 Correct 170 ms 1312 KB Output is correct
5 Correct 178 ms 1484 KB Output is correct
6 Correct 7 ms 448 KB Output is correct
7 Correct 6 ms 440 KB Output is correct
8 Correct 8 ms 360 KB Output is correct
9 Correct 7 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 899 ms 1596 KB Output is correct
2 Correct 1532 ms 1648 KB Output is correct
3 Correct 62 ms 1816 KB Output is correct
4 Correct 31 ms 1836 KB Output is correct
5 Correct 35 ms 2540 KB Output is correct
6 Correct 927 ms 1664 KB Output is correct
7 Correct 859 ms 1668 KB Output is correct
8 Correct 437 ms 1652 KB Output is correct
9 Correct 367 ms 1388 KB Output is correct
10 Correct 374 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 340 KB Output is correct
2 Correct 21 ms 468 KB Output is correct
3 Correct 32 ms 500 KB Output is correct
4 Correct 170 ms 1312 KB Output is correct
5 Correct 178 ms 1484 KB Output is correct
6 Correct 7 ms 448 KB Output is correct
7 Correct 6 ms 440 KB Output is correct
8 Correct 8 ms 360 KB Output is correct
9 Correct 7 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 899 ms 1596 KB Output is correct
12 Correct 1532 ms 1648 KB Output is correct
13 Correct 62 ms 1816 KB Output is correct
14 Correct 31 ms 1836 KB Output is correct
15 Correct 35 ms 2540 KB Output is correct
16 Correct 927 ms 1664 KB Output is correct
17 Correct 859 ms 1668 KB Output is correct
18 Correct 437 ms 1652 KB Output is correct
19 Correct 367 ms 1388 KB Output is correct
20 Correct 374 ms 1384 KB Output is correct
21 Correct 909 ms 1660 KB Output is correct
22 Correct 1516 ms 1648 KB Output is correct
23 Correct 1676 ms 1968 KB Output is correct
24 Correct 662 ms 3008 KB Output is correct
25 Correct 212 ms 3360 KB Output is correct
26 Correct 211 ms 3808 KB Output is correct
27 Correct 59 ms 3032 KB Output is correct
28 Correct 72 ms 2832 KB Output is correct
29 Correct 2794 ms 3508 KB Output is correct
30 Correct 273 ms 3592 KB Output is correct
31 Correct 196 ms 3588 KB Output is correct
32 Correct 214 ms 3624 KB Output is correct
33 Correct 644 ms 3676 KB Output is correct
34 Correct 217 ms 3968 KB Output is correct
35 Correct 201 ms 3656 KB Output is correct
36 Correct 203 ms 3672 KB Output is correct
37 Correct 216 ms 3928 KB Output is correct
38 Correct 935 ms 3740 KB Output is correct
39 Correct 781 ms 3612 KB Output is correct
40 Correct 636 ms 3760 KB Output is correct
41 Correct 2431 ms 3556 KB Output is correct
42 Correct 1540 ms 3684 KB Output is correct
43 Correct 1217 ms 3548 KB Output is correct
44 Correct 1673 ms 2276 KB Output is correct
45 Correct 844 ms 2180 KB Output is correct
46 Correct 539 ms 2472 KB Output is correct
47 Correct 953 ms 2152 KB Output is correct
48 Correct 608 ms 2148 KB Output is correct
49 Correct 364 ms 2404 KB Output is correct