QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599932#6563. Four SquareForever_Young#WA 2ms21748kbC++141.5kb2024-09-29 13:20:442024-09-29 13:20:44

Judging History

This is the latest submission verdict.

  • [2024-09-29 13:20:44]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 21748kb
  • [2024-09-29 13:20:44]
  • Submitted

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\n",x);
    if (x==4) return 1;
    for (int i=0;i<4;i++)
    if (used[i]==0){
        used[i]=1;
        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;
                }
            //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");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 21748kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 7884kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3716kb

input:

2 8
2 8
2 8
2 8

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'