/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 2.75 MiB
#3 Accepted 2ms 2.547 MiB
#4 Accepted 2ms 2.68 MiB
#5 Accepted 2ms 2.527 MiB
#6 Accepted 2ms 2.324 MiB
#7 Accepted 2ms 736.0 KiB
#8 Accepted 2ms 492.0 KiB
#9 Accepted 2ms 332.0 KiB
#10 Accepted 2ms 2.324 MiB
#11 Accepted 2ms 2.328 MiB
#12 Accepted 2ms 584.0 KiB
#13 Accepted 2ms 2.527 MiB
#14 Accepted 2ms 2.527 MiB
#15 Accepted 2ms 2.555 MiB
#16 Accepted 3ms 2.527 MiB
#17 Accepted 2ms 540.0 KiB
#18 Accepted 2ms 2.527 MiB
#19 Accepted 1ms 540.0 KiB
#20 Accepted 2ms 2.574 MiB
#21 Accepted 1ms 540.0 KiB
#22 Accepted 2ms 584.0 KiB
#23 Accepted 1ms 540.0 KiB
#24 Accepted 2ms 2.477 MiB
#25 Accepted 2ms 2.57 MiB
#26 Accepted 2ms 2.527 MiB
#27 Accepted 2ms 2.504 MiB
#28 Accepted 2ms 332.0 KiB
#29 Accepted 1ms 540.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
P1145 Nobita's Love for Shizuka
Contest
LU Divisonal Contest Problem Testing Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-05 06:24:20
Judged At
2024-12-05 06:24:20
Judged By
Score
100
Total Time
3ms
Peak Memory
2.75 MiB