QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528160#4383. LaserxuzhihaodedieAC ✓60ms6688kbC++201.6kb2024-08-23 10:49:052024-08-23 10:49:05

Judging History

你现在查看的是最新测评结果

  • [2024-08-23 10:49:05]
  • 评测
  • 测评结果:AC
  • 用时:60ms
  • 内存:6688kb
  • [2024-08-23 10:49:05]
  • 提交

answer

//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define lson 2*p
#define rson 2*p+1
#define x first
#define y second
#define lowbit(x) x&-x
//#define endl "\n"
const int N=1e6+10;
const int mod=998244353;
int x[N],y[N];
PII p[N];
bool check(PII a,PII b) {
	if(a.x==b.x||a.y==b.y) return true;
	if(a.y-b.y==a.x-b.x||a.y-b.y==b.x-a.x) return true;
	return false;
}
void solve() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y;
	PII res={-1e18,-1e18};
	for(int i=2;i<=n;i++) {
		if(!check(p[1],p[i])) res=p[i];
	}
	if(res.x==-1e18) {
		cout<<"YES"<<endl;
		return ;
	}
	int x1=p[1].x,y1=p[1].y;
	int x2=res.x,y2=res.y;
	vector<PII> v;
	v.push_back({x1,x1-x2+y2});
	if((y1+y2+x1-x2)%2==0&&(y1-y2+x1+x2)%2==0) {
		v.push_back({(y1-y2+x1+x2)/2,(y1+y2+x1-x2)/2});
	} 
	v.push_back({y1-y2+x2,y1});
	v.push_back({x2,x1-x2+y1});
	v.push_back({x2,y1});
	v.push_back({x2+y2-y1,y1});
	v.push_back({x2,x2-x1+y1});
	if((y1+y2+x2-x1)%2==0&&(x1+x2+y2-y1)%2==0) {
		v.push_back({(x1+x2+y2-y1)/2,(y1+y2+x2-x1)/2});
	}
	v.push_back({y2-y1+x1,y2});
	v.push_back({x1,y2});
	v.push_back({x1,x2-x1+y2});
	v.push_back({x1-y2+y1,y2});
	//cout<<p[1].x<<" "<<p[1].y<<" "<<res.x<<" "<<res.y<<endl;
	//cout<<v.size()<<endl;
	for(auto it:v) {
		int flag=1;
		//cout<<it.x<<" "<<it.y<<endl;
		for(int i=1;i<=n;i++) {
			if(!check(it,p[i])) flag=0;
		}
		if(flag) {
			cout<<"YES"<<endl;
			return ;
		}
	}
	cout<<"NO"<<endl;
} 
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 60ms
memory: 6688kb

input:

116
4
-10 0
10 0
5 5
-5 -5
4
-10 0
10 0
0 10
0 -10
4
-1 0
1 0
2 0
3 0
4
0 1
0 2
0 3
0 4
4
100 100
10000 10000
100000 100000
-100 -100
4
-100 100
-10000 10000
-100000 100000
100 -100
6
1 1
1 3
2 2
3 1
3 3
3 4
7
1 1
1 3
2 2
3 1
3 3
1 4
3 4
4
1236833 14678
1232056 9901
1237055 9790
1231834 15011
4
1236...

output:

YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO...

result:

ok 116 lines