QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#524023 | #9134. Building a Fence | daduoli# | WA | 6ms | 3884kb | C++14 | 1.4kb | 2024-08-19 08:30:36 | 2024-08-19 08:30:37 |
Judging History
answer
#include<bits/stdc++.h>
#define Yzl unsigned long long
typedef long long LL;
using namespace std;
const Yzl Lty=20120712;
int w,h,s,sum;
int a[6],ans,b[6],vis[6],anss;
void rdfs(int u,int ls) {
if(u>4) {
anss=min(anss,ls);
// cout<<b[1]<<" "<<b[2]<<' '<<b[3]<<" "<<b[4]<<':'<<ls<<endl;
return ;
}
ls+=b[u]/s;
// if(b[1]==7&&b[2]==7&&u==3) {
// cout<<ls<<' '<<b[u]/s<<' '<<b[4]<<endl;
// }
int co=s-b[u]%s;
if(co==s) {
rdfs(u+1,ls);
return ;
}
++ls;
for(int i=u+1;i<=4;++i) {
if(b[i]>=co) {
b[i]-=co;
// if(u==2&&i==4) {
// cout<<b[i]<<' ';
// }
// if(u==1&&i==3) {
// cout<<b[i]<<" ";
// }
rdfs(u+1,ls);
b[i]+=co;
}
}
rdfs(u+1,ls);
}
void dfs(int u) {
if(u>4) {
// cout<<b[1]<<" "<<b[2]<<" "<<b[3]<<' '<<b[4]<<endl;
// cout<<114514<<' ';
rdfs(1,0);
// exit(0);
return ;
}
for(int i=1;i<=4;++i) {
if(!vis[i]) {
if((i==2&&!vis[1])||(i==4&&!vis[3])) continue;
b[u]=a[i];
vis[i]=1;
dfs(u+1);
vis[i]=0;
}
}
}
void vmain() {
scanf("%d%d%d",&w,&h,&s);
ans=0;
int ls=w/s;
if(ls>=4) {
ans+=(ls-4)*2;
w-=(ls-4)*s;
}
ls=h/s;
if(ls>=4) {
ans+=(ls-4)*2;
h-=(ls-4)*ls;
}
if(h>w) swap(h,w);
memset(vis,0,sizeof(vis));
a[1]=h; a[2]=h;
a[3]=w; a[4]=w;
anss=1e9; dfs(1);
printf("%d\n",ans+anss);
}
int main () {
int T;
scanf("%d",&T);
while(T--) vmain();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
7 7 9 4 1 1 2 1 1 4 4 6 2 3 3 5 10 6 4 1 11 5
output:
8 2 4 10 4 8 5
result:
ok 7 numbers
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 3884kb
input:
8000 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 17 1 1 18 1 1 19 1 1 20 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 2 10 1 2 11 1 2 12 1 2 13 1 2 14 1 2 15 1 2 16 1 2 17 1 2 18 1 2 19 1 2 20 1 3 1 1 3 2 1 3 3 1 3 4 1 3 5 1 3...
output:
4 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6 3 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 8 4 4 2 4 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 10 5 4 4 2 4 4 3 4 4 4 4 4 4 4 4 4 4 4 4 4 6 4 3 4 2 4 4 4 3 4 4 4 4 4 4 4 4 4 4 -6 7 5 4 4 4 2 4 4 4 4 3 4 4 4 4 4 4 4 4 -20 8 6 4 4 4 4 2 4 4 4 4 4 3 4 4 4 4 4 4 -38 9 6 5 4 3 4 ...
result:
wrong answer 81st numbers differ - expected: '12', found: '4'