QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188919 | #6563. Four Square | ucup-team870# | AC ✓ | 1ms | 3556kb | C++14 | 1.9kb | 2023-09-26 16:46:48 | 2023-09-26 16:46:49 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
struct P{
int x,y;
};
#define vp vector<P>
bool ck2(vp q,int X,int Y){
// cout<<X<<' '<<Y<<endl;
// for(auto [x,y]:q)cout<<x<<' '<<
int v1[2]={q[0].x,q[0].y},v2[2]={q[1].x,q[1].y};
rep(i,0,1){
rep(j,0,1){
if(v1[i]!=v2[j])continue;
int x=v1[i],y=v1[1-i]+v2[1-j];
if((x==X && y==Y) || (x==Y && y==X))return true;
}
}
return false;
}
bool ck3(vp q,int X,int Y){
// for(auto [x,y]:q){
// cout<<x<<' '<<y<<'\n';
// }
rep(i,0,2){
vp qi; rep(j,0,2){if(j!=i)qi.push_back(q[j]);}
int v[2]={q[i].x,q[i].y}; int b[2]={X,Y};
rep(j,0,1){
rep(k,0,1){
if(v[j]==b[k]){
if(ck2(qi, v[j],b[1-k]-v[1-j]))return true;
}
}
}
}
return false;
}
P a[4]; int L;
P q[4]; int vis[4];
void dfs(int i){
if(i==4){
rep(j,0,3){
if(q[j].x+q[(j+1)%4].y!=L)return;
}
cout<<1; exit(0);
}
rep(j,0,3){
if(!vis[j]){
q[i]=a[j]; vis[j]=1;
dfs(i+1); vis[j]=0;
q[i]={a[j].y,a[j].x}; vis[j]=1;
dfs(i+1); vis[j]=0;
}
}
}
int main() {
IOS
int s=0;
rep(i,0,3){
cin>>a[i].x>>a[i].y;
if(a[i].x<a[i].y)swap(a[i].x,a[i].y);
s+=a[i].x*a[i].y;
}
L=sqrt(s)+2;
while(L*L>s)--L;
if(L*L!=s){
cout<<0; return 0;
}
rep(i,0,3){
if(a[i].x==L){
vp q;
rep(j,0,3){
if(i!=j)q.push_back(a[j]);
}
if(ck3(q,L,L-a[i].y))cout<<1; else cout<<0; return 0;
}
}
dfs(0);
cout<<0;
}
/*
6 2
4 2
4 3
4 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3452kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
1000 999 998 1000 997 1000 997 997
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
1 3 3 3 3 3 4 7
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
2 5 5 4 7 1 6 2
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
12 2 12 7 7 12 16 4
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
7 2 2 14 5 14 7 12
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
32 36 5 1 1 37 35 5
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
28 30 30 1 31 1 2 30
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
66 68 9 11 7 66 9 64
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
59 44 25 44 40 32 40 52
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
4 4 2 3 4 2 3 2
output:
1
result:
ok single line: '1'