/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 412.0 KiB
#2 Wrong Answer 1ms 556.0 KiB

Code

// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define endl '\n'

using namespace std;
using pii = pair<int, int>;
using tup = tuple<int, int, int>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> using ordered_set = tree<T, null_type,
                         less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 1e18;
const int mod = 1000000007;
const double eps = 1e-9;
const int N = 200005;

void preprocess() {}

// AId the code

int px[N], py[N];

bool onLine(int x1, int y1, int x2, int y2, int px, int py) {
    if ((px - x1) * (y2 - y1) == (py - y1) * (x2 - x1)) {
        return px >= min(x1, x2) && px <= max(x1, x2) &&
               py >= min(y1, y2) && py <= max(y1, y2);
    }
    return false;
}

bool pointInPolygon(int n, int x, int y) {
    bool inside = false;
    for (int i = 1, j = n; i <= n; j = i++) {
        int x1 = px[i], y1 = py[i];
        int x2 = px[j], y2 = py[j];
        
        if (onLine(x1, y1, x2, y2, x, y)) return false;

        if ((y1 > y) != (y2 > y)) {
            double xinters = (double)(x2 - x1) * (y - y1) / (y2 - y1) + x1;
            if (xinters > x) inside = !inside;
        }
    }
    return inside;
}

void solve(int tc) {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> px[i] >> py[i];
    }

    int x, y;
    cin >> x >> y;

    if (pointInPolygon(n, x, y)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int32_t main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cout.precision(10);

    preprocess(); 

    int T = 1;
    // cin >> T;

    for (int i = 1; i <= T; i++) {
        solve(i);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1144 Palindromic Distance
Contest
LU Divisonal Contest Problem Testing Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-05 06:24:02
Judged At
2024-12-05 06:24:02
Judged By
Score
0
Total Time
1ms
Peak Memory
556.0 KiB