QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165468 | #6563. Four Square | PhantomThreshold# | WA | 1ms | 3540kb | C++20 | 1.6kb | 2023-09-05 18:29:19 | 2023-09-05 18:29:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
/*
ll pw(ll a,ll x){
ll ret=1;
for (;x;x>>=1,a=a*a) if (x&1) ret=ret*a;
return ret;
}
*/
ll sq(ll x){
ll sz=sqrt(x);
for (;(sz+1)*(sz+1)<=x;) sz++;
for (;sz*sz>x;) sz--;
return sz;
}
pii a[10];
int main(){
for (int i=1;i<=4;i++){
ll w,h;
cin >> w >> h;
if (w<h) swap(w,h);
a[i]=make_pair(w,h);
}
sort(a+1,a+4+1,
[&](const pii &A,const pii &B){
return A>B;
}
);
ll area=0;
for (int i=1;i<=4;i++) area+=a[i].first*a[i].second;
ll sz=sq(area);
if (sz*sz!=area){
cout << 0 << "\n";
return 0;
}
ll pos=0;
for (int i=1;i<=4;i++) if (a[i].first==sz) pos=i;
if (pos!=0){
ll m=sz;
for (int i=1;i<=pos;i++) m-=a[i].second;
ll n=sz;
for (int i=pos+1;i<=4;i++){
if (a[i].first==m) n-=a[i].second;
else if (a[i].second==m) n-=a[i].first;
else{
cout << 0 << "\n";
return 0;
}
}
if (n==0) cout << 1 << "\n";
else cout << 0 << "\n";
}
else{
vector<pii> b(10);
do{
for (int mask=0;mask<(1<<4);mask++){
for (int i=1;i<=4;i++){
b[i]=a[i];
if ((mask>>(i-1))&1){
swap(b[i].first,b[i].second);
}
}
if (b[1].first+b[2].first!=sz) continue;
if (b[1].second!=b[2].second) continue;
if (b[3].first+b[4].first!=sz) continue;
if (b[3].second!=b[4].second) continue;
if (b[1].second+b[3].second!=sz) continue;
cout << 1 << "\n";
return 0;
}
}while (next_permutation(a+1,a+4+1));
cout << 0 << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3436kb
input:
2 8 2 8 2 8 2 8
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'