| Task: | Point in Polygon |
| Sender: | rikachu |
| Submission time: | 2025-11-10 17:27:43 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | WRONG ANSWER | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | WRONG ANSWER | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | WRONG ANSWER | 0.00 s | details |
| #7 | WRONG ANSWER | 0.00 s | details |
| #8 | WRONG ANSWER | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | WRONG ANSWER | 0.00 s | details |
| #11 | WRONG ANSWER | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | UNKNOWN | -- | details |
Compiler report
input/code.cpp: In function 'bool do_intersect(pt, pt, pt, pt, bool&)':
input/code.cpp:115:30: warning: unused variable 'x' [-Wunused-variable]
115 | auto x = (c1 * b2 - c2 * b1) / det;
| ^
input/code.cpp:116:30: warning: unused variable 'y' [-Wunused-variable]
116 | auto y = (a1 * c2 - a2 * c1) / det;
| ^
input/code.cpp: In function 'int main()':
input/code.cpp:133:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
133 | for (size_t i = 0; i < n; i++) {
| ~~^~~
input/code.cpp:140:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
140 | for (size_t i = 0; i < m; i++) {
| ~~^~~Code
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(0), cin.tie(0)
const int INF = 1001001001;
const int MAXN = 100'000;
const char br = '\n';
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
// === Debug macro starts here ===
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) \
{ \
++recur_depth; \
auto x_ = x; \
--recur_depth; \
cerr << string(recur_depth, '\t') << "\e[91m" << __func__ \
<< ":" << __LINE__ << "\t" << #x << " = " << x_ \
<< "\e[39m" << endl; \
}
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream &>::type
operator<<(Ostream &os, const Cont &v) {
os << "[";
for (auto &x : v) {
os << x << ", ";
}
return os << "]";
}
// === Debug macro ends here ===
// print pair, vector
template <typename Ostream, typename... Ts>
Ostream &operator<<(Ostream &os, const pair<Ts...> &p) {
return os << "{" << p.first << ", " << p.second << "}";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
for (const T &v : t) {
cout << v << " ";
}
return s;
}
int nxt() {
int x;
cin >> x;
return x;
}
using C = long long;
using pt = complex<C>;
#define X real()
#define Y imag()
C dist(pt a, pt b) { return abs(b - a); }
C cross(pt a, pt b) { return (conj(a) * b).Y; }
int orientation(pt p, pt q, pt r) {
auto val = (q.Y - p.Y) * (r.X - q.X) - (q.X - p.X) * (r.Y - q.Y);
if (val == 0)
return 0;
return (val > 0) ? 1 : 2;
}
bool on_segment(pt p, pt q, pt r) {
if (q.X <= max(p.X, r.X) && q.X >= min(p.X, r.X) &&
q.Y <= max(p.Y, r.Y) && q.Y >= min(p.Y, r.Y))
return true;
return false;
}
bool do_intersect(pt p1, pt q1, pt p2, pt q2, bool &boundary) {
auto o1 = orientation(p1, q1, p2);
auto o2 = orientation(p1, q1, q2);
auto o3 = orientation(p2, q2, p1);
auto o4 = orientation(p2, q2, q1);
boundary = true;
if (o1 == 0 && on_segment(p1, p2, q1))
return true;
if (o2 == 0 && on_segment(p1, q2, q1))
return true;
if (o3 == 0 && on_segment(p2, p1, q2))
return true;
if (o4 == 0 && on_segment(p2, q1, q2))
return true;
boundary = false;
if (o1 != o2 && o3 != o4) {
auto a1 = q1.Y - p1.Y;
auto b1 = p1.X - q1.X;
auto c1 = a1 * p1.X + b1 * p1.Y;
auto a2 = q2.Y - p2.Y;
auto b2 = p2.X - q2.X;
auto c2 = a2 * p2.X + b2 * p2.Y;
auto det = a1 * b2 - a2 * b1;
if (det != 0) {
auto x = (c1 * b2 - c2 * b1) / det;
auto y = (a1 * c2 - a2 * c1) / det;
return true;
}
}
return false;
}
int main() {
IOS;
int n = nxt();
int m = nxt();
vector<pt> pts(n);
vector<pt> queries(m);
for (size_t i = 0; i < n; i++) {
C a, b;
cin >> a >> b;
pts[i] = {a, b};
}
pts.push_back(pts[0]);
for (size_t i = 0; i < m; i++) {
C a, b;
cin >> a >> b;
queries[i] = {a, b};
}
for (size_t i = 0; i < queries.size(); i++) {
pt pt_at_inf = {INF, INF};
pt q = queries[i];
int count = 0;
bool boundary = false;
for (size_t j = 0; j < pts.size() - 1; j++) {
pt seg0 = pts[j];
pt seg1 = pts[j + 1];
if(do_intersect(q, pt_at_inf, seg0, seg1, boundary)) {
count++;
if (boundary) {
break;
}
} else if (on_segment(q,seg0, seg1)) {
boundary = true;
break;
}
}
if (boundary)
cout << "BOUNDARY" << br;
else if (count % 2 == 1) {
cout << "INSIDE" << br;
} else {
cout << "OUTSIDE" << br;
}
}
return 0;
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 100 1000 -7 -19 91 77 100 100 64 60 ... |
| correct output |
|---|
| INSIDE OUTSIDE INSIDE INSIDE INSIDE ... |
| user output |
|---|
| BOUNDARY BOUNDARY BOUNDARY BOUNDARY BOUNDARY ... |
Feedback: Incorrect character on line 1 col 1: expected "INSIDE", got "BOUNDARY"
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 1000 1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
| correct output |
|---|
| OUTSIDE OUTSIDE INSIDE OUTSIDE OUTSIDE ... |
| user output |
|---|
| BOUNDARY BOUNDARY BOUNDARY BOUNDARY BOUNDARY ... |
Feedback: Incorrect character on line 1 col 1: expected "OUTSIDE", got "BOUNDARY"
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 4 1 1 5 5 5 5 1 1 1 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "INSIDE", got "BOUNDARY"
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 4 1 1 5 5 5 5 1 1 1 ... |
| correct output |
|---|
| OUTSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "OUTSIDE", got "BOUNDARY"
Test 5
Verdict: ACCEPTED
| input |
|---|
| 4 1 1 100 2 50 1 20 0 50 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 8 1 0 0 0 2 1 1 2 2 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "INSIDE", got "BOUNDARY"
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 4 4 0 0 3 0 3 4 0 4 ... |
| correct output |
|---|
| INSIDE BOUNDARY OUTSIDE BOUNDARY |
| user output |
|---|
| INSIDE BOUNDARY BOUNDARY BOUNDARY |
Feedback: Incorrect character on line 3 col 1: expected "OUTSIDE", got "BOUNDARY"
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 6 1 0 0 0 2 3 1 2 2 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "INSIDE", got "BOUNDARY"
Test 9
Verdict: ACCEPTED
| input |
|---|
| 3 1 0 0 1 1000000000 -3 0 1 1 |
| correct output |
|---|
| OUTSIDE |
| user output |
|---|
| OUTSIDE |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 3 1 -100000 0 -1000000000 -999999999 1000000000 1000000000 0 0 |
| correct output |
|---|
| OUTSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "OUTSIDE", got "BOUNDARY"
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 3 1 -100000 0 -999999999 -1000000000 1000 1000 0 0 |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| BOUNDARY |
Feedback: Incorrect character on line 1 col 1: expected "INSIDE", got "BOUNDARY"
Test 12
Verdict: ACCEPTED
| input |
|---|
| 4 1 -4 1 -6 1 -6 -1 -4 -1 ... |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 3 1 0 10 0 -10 10 0 1 0 |
| correct output |
|---|
| INSIDE |
| user output |
|---|
| INSIDE |
Test 14
Verdict: UNKNOWN
| input |
|---|
| 3 1000 -536621709 -536621709 955833081 955833081 -1 1 -439278425 -439278425 ... |
| correct output |
|---|
| BOUNDARY BOUNDARY BOUNDARY BOUNDARY BOUNDARY ... |
| user output |
|---|
| (not available) |
