QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599935 | #6563. Four Square | Forever_Young# | WA | 39ms | 21680kb | C++14 | 1.6kb | 2024-09-29 13:24:50 | 2024-09-29 13:24:51 |
Judging History
answer
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int w[4],h[4],sum,wid,used[4],f[5][1010][1010];
pair<int,int> lu;
int dfs(int x){
//printf("gg %d %d\n",wid,x);
if (x==4) return 1;
for (int i=0;i<4;i++)
if (used[i]==0){
used[i]=1;
lu=mp(0,0);
for (int j=0;j<wid;j++){
for (int k=0;k<wid;k++)
if (f[x][j][k]==0){
lu=mp(j,k);
break;
}
if (f[x][lu.fi][lu.se]==0) break;
}
//printf("%d %d\n",lu.fi,lu.se);
int can=1;
if (lu.fi+w[i]<=wid&&lu.se+h[i]<=wid){
memcpy(f[x+1],f[x],sizeof(f[x]));
for (int j=lu.fi;j<lu.fi+w[i];j++)
for (int k=lu.se;k<lu.se+h[i];k++)
if (f[x+1][j][k]==1) can=0;
else f[x+1][j][k]=1;
if (can==1&&dfs(x+1)==1) return 1;
}
can=1;
if (lu.fi+h[i]<=wid&&lu.se+w[i]<=wid){
memcpy(f[x+1],f[x],sizeof(f[x]));
for (int j=lu.fi;j<lu.fi+h[i];j++)
for (int k=lu.se;k<lu.se+w[i];k++)
if (f[x+1][j][k]==1) can=0;
else f[x+1][j][k]=1;
if (can==1&&dfs(x+1)==1) return 1;
}
used[i]=0;
}
return 0;
}
int main(){
//freopen("F.in","r",stdin);
for (int i=0;i<4;i++){
scanf("%d%d",&w[i],&h[i]);
sum+=w[i]*h[i];
}
wid=sqrt(sum);
if (wid*wid==sum&&dfs(0)) printf("1\n");
else printf("0\n");
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 20312kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 23ms
memory: 21200kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 21680kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 5ms
memory: 21288kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 36ms
memory: 21432kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 14096kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 10ms
memory: 18060kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 23ms
memory: 18088kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 7ms
memory: 14036kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 13ms
memory: 20368kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 20ms
memory: 20536kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 21ms
memory: 21188kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: -100
Wrong Answer
time: 39ms
memory: 14016kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'