/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Wrong Answer 2ms 544.0 KiB
#5 Accepted 1ms 424.0 KiB
#6 Accepted 1ms 540.0 KiB
#7 Accepted 1ms 332.0 KiB
#8 Wrong Answer 2ms 348.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long

int area(int a, int b, int c, int d, int e, int f) {
    int val = a * d + c * f + e * b - b * c - d * e - a * f;
    return abs(val);
}

int f(int a, int b, int x1, int y1, int x2, int y2) {
    int left = (b - y1) * (x1 - x2);
    int right = (a - x1) * (y1 - y2);
    if(left == right) return 1;
    return 0;
}

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

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    int xx, yy;
    cin >> xx >> yy;

    int a = 0;

    for (int i = 0; i + 1 < n; i++) {
        a += x[i] * y[i + 1];
    }
    a += x[n - 1] * y[0];

    for (int i = 0; i + 1 < n; i++) {
        a -= y[i] * x[i + 1];
    }

    a -= x[0] * y[n - 1];
    int b = 0;


    for (int i = 0; i + 1 < n; i++) {
        b += area(x[i], y[i], x[i + 1], y[i + 1], xx, yy);
    }

    b += area(x[0], y[0], x[n - 1], y[n - 1], xx, yy);

    bool ok = 0;
    for (int i = 0; i + 1 < n; i++) {
        ok |= f(xx, yy,x[i], y[i], x[i + 1], y[i + 1]);
    }
    ok |= f(xx, yy,x[0], y[0], x[n -1], y[n - 1]);

    if(ok) cout << "NO\n";

    else if(abs(a) == b) {
        cout << "YES\n";
    }
    else cout << "NO\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; 
    //cin>>t;
    for(int tc = 1; tc <= t; tc++) {
        // cout<<"Case "<<tc<<":";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1145 Nobita's Love for Shizuka
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 09:39:20
Judged At
2024-12-09 09:39:20
Judged By
Score
20
Total Time
2ms
Peak Memory
544.0 KiB