QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#587231 | #9134. Building a Fence | Djangle162857 | WA | 0ms | 3944kb | C++14 | 1.4kb | 2024-09-24 18:36:48 | 2024-09-24 18:36:49 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
const int inf=1000000000;
ll w,h,s;
inline ll solve(ll x,ll y,ll s)
{
if(x>y)swap(x,y);
if(!x&&!y)return 0;
if(!x)
{
return y/s+(y%s!=0);
}
if(x+y==s)return 1;
ll res=x/s;
if(x%s)
{
res++;
if(y>=(x/s+1)*s-x)
y-=((x/s+1)*s-x);
if(y==0)return res;
}
res+=y/s;
if(y%s)res++;
return res;
}
int main()
{
//cout<<solve(1,1,4)<<endl;
int T;
scanf("%d",&T);
for(int _=1;_<=T;_++)
{
ll ans=0;
scanf("%lld%lld%lld",&w,&h,&s);
//if(_==863)
{
// cout<<w<<'0'<<h<<'0'<<s<<endl;
}
if(w>=s&&h>=s)
{
if((2*(w+h))%s==0)ans=(2*(w+h))/s;
else ans=(2*(w+h))/s+1;
printf("%lld\n",ans);
continue;
}
if(w>h)swap(w,h);
ans=1ll*inf;
ans=min(ans,2ll+solve(h,h,s));
if(s>=w&&(s-w)<=h)
cout<<2ll+solve(h-(s-w),h-(s-w),s)<<endl,
ans=min(ans,2ll+solve(h-(s-w),h-(s-w),s));
if(s>=w&&2*(s-w)<=h)
cout<<2ll+solve(h-2*(s-w),h,s)<<endl,
ans=min(ans,2ll+solve(h-2*(s-w),h,s));
if(s>=h&&s-h<=w)
cout<<2ll+solve(w-(s-h),w-(s-h),s)<<endl,
ans=min(ans,2ll+solve(w-(s-h),w-(s-h),s));
if(s>=h&&2*(s-h)<=w)
cout<<2ll+solve(w,w-2*(s-h),s)<<endl,
ans=min(ans,2ll+solve(w,w-2*(s-h),s));
printf("%lld\n",ans);
}
return 0;
}
/*
7
7 9 4
1 1 2
1 1 4
4 6 2
3 3 5
10 6 4
1 11 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3944kb
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 2 2 4 10 4 4 4 8 5 5 5
result:
wrong answer 3rd numbers differ - expected: '4', found: '2'