QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354661 | #6563. Four Square | Delay_for_five_minutes# | AC ✓ | 3ms | 3828kb | C++20 | 2.9kb | 2024-03-15 20:40:55 | 2024-03-15 20:40:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n , m;
typedef pair<int,int> pii;
typedef long long ll;
pii s[4];
int st[4];
bool used[4];
bool sol = 0;
int w = -1 ,h = -1;
bool chk() {
pii ns[4] ;
for(int i = 0;i < 4;i++) {
if(st[i] & 1) ns[i] = {s[i].second , s[i].first} ;
else ns[i] = s[i];
}
map<pii,int> mp;
mp[{0,0}] = 0 ; mp[{0 , w}] = 0;mp[{w , 0}] = 0;mp[{w , w}] = 0;
for(int i = 0;i < 4;i++) {
pii tl ;
int cur = (st[i] >> 1);
if(cur == 0) tl = {0 , 0};
else if(cur == 1) tl = {0 , w - ns[i].second} ;
else if(cur == 2) tl = {w - ns[i].first, 0};
else tl = {w - ns[i].first , w - ns[i].second};
mp[tl]++ ;
mp[{tl.first + ns[i].first , tl.second}]--;
mp[{tl.first , tl.second + ns[i].second}]--;
mp[{tl.first + ns[i].first , tl.second + ns[i].second}]++ ;
}
for(auto &[u,v] : mp) {
if(u == (pii){0,0} || u == (pii){w,w}) {
if(v != 1) return 0;
}
else if(u == (pii){0,w} || u == (pii){w,0}) {
if(v != -1) return 0;
}
else {
if(v != 0) return 0;
}
}
return 1;
}
void dfs(int u) {
if(u == 4) {
sol |= chk() ;
return ;
}
for(int i = 0;i < 8;i++) {
st[u] = i;dfs(u + 1);
}
return ;
}
int lw , lh;
void ddfs(int u) {
if(u == 4) {
if(lw == 0 || lh == 0) sol = 1;
return ;
}
// printf("in %d %d %d\n",u,lw,lh) ;
for(int i = 0;i < 4;i++) {
if(used[i]) continue ;
// printf("%d %d\n",s[i].first,s[i].second) ;
if(s[i].first == lw) {
used[i] = 1 ;
lh -= s[i].second ;
ddfs(u + 1) ;
lh += s[i].second ;
used[i] = 0;
}
if(s[i].first == lh) {
used[i] = 1 ;
lw -= s[i].second ;
ddfs(u + 1) ;
lw += s[i].second ;
used[i] = 0;
}
if(s[i].second == lw) {
used[i] = 1 ;
lh -= s[i].first ;
ddfs(u + 1) ;
lh += s[i].first;
used[i] = 0;
}
if(s[i].second == lh) {
used[i] = 1 ;
lw -= s[i].first ;
ddfs(u + 1) ;
lw += s[i].first;
used[i] = 0;
}
}
}
int main() {
ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
ll ans = 0;
for(int i = 0;i < 4;i++) {cin >> s[i].first >> s[i].second ; ans += 1LL * s[i].first * s[i].second ;}
int d = sqrt(ans) ;
for(int i = max(1 , d - 1) ; i <= d + 1;i++) {
if(1LL * i * i == ans) {
w = i;h = i;
}
}
if(w == -1) {cout << 0 ; return 0;}
dfs(0) ;
if(sol) {
cout << 1 ; return 0;
}
lw = w ; lh = w;
ddfs(0) ;
cout << sol ;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3548kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3552kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3508kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3828kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3508kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3548kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3540kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3496kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3544kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 3ms
memory: 3764kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3536kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3536kb
input:
1000 999 998 1000 997 1000 997 997
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
1 3 3 3 3 3 4 7
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 3ms
memory: 3536kb
input:
2 5 5 4 7 1 6 2
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 3ms
memory: 3612kb
input:
12 2 12 7 7 12 16 4
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3552kb
input:
7 2 2 14 5 14 7 12
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 3ms
memory: 3800kb
input:
32 36 5 1 1 37 35 5
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3504kb
input:
28 30 30 1 31 1 2 30
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Accepted
time: 3ms
memory: 3604kb
input:
66 68 9 11 7 66 9 64
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3540kb
input:
59 44 25 44 40 32 40 52
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 3ms
memory: 3824kb
input:
4 4 2 3 4 2 3 2
output:
1
result:
ok single line: '1'