/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 516.0 KiB
#3 Accepted 1ms 560.0 KiB
#4 Wrong Answer 2ms 496.0 KiB
#5 Accepted 1ms 768.0 KiB
#6 Accepted 2ms 540.0 KiB
#7 Accepted 2ms 556.0 KiB
#8 Wrong Answer 1ms 540.0 KiB

Code

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

#define ll long long
#define bug(a) cout << #a << " : " << a << endl;

vector<pair<ll,ll>> point;
pair<ll,ll> p;
ll tri_sum(pair<ll,ll> p1,pair<ll,ll> p2){
   ll sum = ((p1.first*p2.second) + (p2.first * p.second )+( p.first*p1.second));
   sum -= ((p1.second*p2.first) +( p2.second * p.first )+ (p.second*p1.first));
   return abs(sum);
}
ll get(){

	ll sum1 = 0, sum2 = 0;
	int n = point.size();
	for(int i = 0; i < n; i++){
		if ( i == n-1 ) {
			sum1 += (1LL * point[i].first * point[0].second);
		}
		else{
			sum1 += (1LL * point[i].first * point[i + 1].second);
		}

		if ( i == n-1 ) {
			sum2 += (1LL * point[i].second * point[0].first);
		} 
		else {
			sum2 += (1LL * point[i].second * point[i + 1].first);
		}
	}
	ll ans = abs(sum1 - sum2);
	return ans;

}

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

	for(int i = 1; i <= n; i++){
		int x, y;	cin >> x >> y;
		point.push_back({x, y});
	}

	
	cin >> p.first >> p.second;

	ll area = get();

	ll area_upd = 0;
	int flag = 0;
	for(int i = 0; i < n;i++){
     ll ar = 0;

	   if(i == n-1){
	    ar =  tri_sum(point[i],point[0]);
	   }
	   else{
	     ar = tri_sum(point[i],point[i+1]);
	   }
    
	   if(ar == 0){
	  	flag = 1;
	  	break;
	   }
	  area_upd += ar;
	}


	if(area == area_upd && flag == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int tc = 1, cs = 0;
	// cin >> tc;

	while(tc--){
		//cout << "Case # " << ++cs << ": " ;
		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 07:34:04
Judged At
2024-12-09 07:34:04
Judged By
Score
20
Total Time
2ms
Peak Memory
768.0 KiB