QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130636 | #5073. Elden Ring | PetroTarnavskyi# | WA | 1ms | 3512kb | C++17 | 2.2kb | 2023-07-24 18:27:56 | 2023-07-24 18:27:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
struct Point {
int x, y;
Point() {}
Point(int _x, int _y): x(_x), y(_y) {}
Point operator-(const Point& p) const {
return {x - p.x, y - p.y};
}
LL operator* (const Point& p) const {
return (LL)x * p.y - (LL)p.x * y;
}
void read() {
cin >> x >> y;
}
};
int sign(LL x) {
if (x == 0) {
return 0;
}
else if (x > 0) {
return 1;
}
else {
return -1;
}
}
bool intersect(const Point& a, const Point& b, const Point& c, const Point& d) {
if (sign((b - a) * (c - a)) * sign((b - a) * (d - a)) > 0) {
return false;
}
if (sign((d - c) * (a - c)) * sign((d - c) * (b - c)) > 0) {
return false;
}
return min(a.x, b.x) <= max(c.x, d.x) && min(a.y, b.y) <= max(c.y, d.y)
&& min(c.x, d.x) <= max(a.x, b.x) && min(c.y, d.y) <= max(a.y, b.y);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
Point a, b, c, d, e, f;
a.read();
b.read();
c.read();
d.read();
e.read();
f.read();
if (!intersect(a, b, c, d) && !intersect(a, b, e, f)) {
cout << "0\n";
continue;
}
if (!intersect(c, d, e, f)) {
cout << "1\n";
continue;
}
vector<Point> vec[2];
for (const Point& p : {c, d, e, f}) {
LL prod = (b - a) * (p - a);
if (prod > 0) {
vec[0].push_back(p);
}
else if (prod < 0) {
vec[1].push_back(p);
}
}
if (SZ(vec[0]) < 2 || SZ(vec[1]) < 2) {
cout << "1\n";
continue;
}
int ans = 2;
FOR(it, 0, 2) {
Point p1 = (vec[it][0] - a) * (vec[it][1] - a) > 0 ? vec[it][1] : vec[it][0];
Point p2 = (vec[it][0] - b) * (vec[it][1] - b) > 0 ? vec[it][0] : vec[it][1];
if ((p1 - a) * (p2 - b) > 0) {
ans = 1;
}
swap(a, b);
}
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3512kb
input:
2 5 4 5 8 1 2 1 3 1 4 4 5 15 1 1 1 1 5 4 10 5 1 2 1 3 1 4 4 5 10 4 4 4 19
output:
0 1
result:
wrong answer 1st numbers differ - expected: '2', found: '0'