/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 560.0 KiB
#2 Accepted 3ms 2.348 MiB
#3 Accepted 1ms 540.0 KiB
#4 Wrong Answer 3ms 2.48 MiB
#5 Accepted 2ms 572.0 KiB
#6 Accepted 2ms 496.0 KiB
#7 Accepted 1ms 332.0 KiB
#8 Wrong Answer 2ms 492.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];

int triangleArea(int x1, int y1, int x2, int y2, int x3, int y3) {
    int area = abs(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2));
    return area;
}

bool onLine(int x1, int y1, int x2, int y2, int px, int py) {
    // Check if the point (px, py) is collinear with the segment (x1, y1) to (x2, y2)
    if ((px - x1) * (y2 - y1) == (py - y1) * (x2 - x1)) {
        // Ensure the point is within the bounds of the line segment
        return px >= min(x1, x2) && px <= max(x1, x2) &&
               py >= min(y1, y2) && py <= max(y1, y2);
    }
    return false;
}

int polygonArea(int n, int px[], int py[]) {
    int area = 0;
    for(int i = 1; i < n; i++) {
        area += px[i] * py[i+1] - px[i+1] * py[i];
    }
    area += px[n] * py[1] - px[1] * py[n];
    return abs(area);
}

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;
    
    bool onAnyLine = false;
    for(int i = 1; i <= n; i++) {
        int j = (i == n) ? 1 : i + 1;
        if(onLine(px[i], py[i], px[j], py[j], x, y)) {
            onAnyLine = true;
            break;
        }
    }
    
    if(onAnyLine) {
        cout << "NO" << endl;
        return;
    }
    
    int totalArea = polygonArea(n, px, py);
    
    int sumTriangleAreas = 0;
    for(int i = 1; i <= n; i++) {
        int j = (i == n) ? 1 : i + 1;
        sumTriangleAreas += triangleArea(x, y, px[i], py[i], px[j], py[j]);
    }
    
    if(sumTriangleAreas == totalArea) {
        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:36:36
Judged At
2024-12-05 06:36:36
Judged By
Score
20
Total Time
3ms
Peak Memory
2.48 MiB