QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611714#9134. Building a FenceWarrnaCuteWA 2ms3632kbC++141.7kb2024-10-04 22:17:382024-10-04 22:17:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 22:17:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3632kb
  • [2024-10-04 22:17:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18;
int solve(int a,int b,int c)
{
	if(a==0&&b==0) return 0;
    if(a+a==c) return 1+1+(b+b!=c);
	if(a==0) return 1+(b+b!=c);
	if(b==0) return 1+(a+a!=c);
	int less=c-a;
	if(b<less) return 4;
	if(b==less) return 2;
	if(b<less+less) return 4;
	if(b==less+less) return 3;
	if(b==(c-b)+less+less) return 3;
	return 4;
}
int solve2(int a,int b,int c)
{
	int less=c-b;
	if(less+less==a) return 3;
	return inf;
}
int solve3(int a,int b,int c)
{
	int less=c-b+c-b+c-a%c;
	if(less==a) return 3;
	return inf;
}
int solve4(int a,int b,int c)
{
	int less=c-b;
	if(less+less>=a||a-less-less>=c) return inf;
	int lesss=a-less-less;
	if(a-lesss<0) return inf;
	if(a-lesss==0) return 3;
	return 4;
}
int solve5(int a,int b,int c)
{
	int less=c-b;
	if(less+less>=a||a-less-less>=c) return inf;
	int lesss=a-less-less;
	if(a-c-lesss>c) return inf;
	return 4;
}
void solve()
{
	int x,y,c,ans=0;
	cin>>x>>y>>c;
	int a=x%c,b=y%c;
	ans=2*(x/c+y/c)+min(solve(a,b,c),solve(b,a,c));
	if(a+c<=x) ans=min(ans,2*(x/c+y/c)-1+solve2(a+c,b,c));
	if(b+c<=y) ans=min(ans,2*(x/c+y/c)-1+solve2(b+c,a,c));
	if(a+2*c<=x) ans=min(ans,2*(x/c+y/c)-2+solve3(a+2*c,b,c));
	if(b+2*c<=y) ans=min(ans,2*(x/c+y/c)-2+solve3(b+2*c,a,c));
	if(a+c<=x) ans=min(ans,2*(x/c+y/c)-2+solve4(a+c,b,c));
	if(b+c<=y) ans=min(ans,2*(x/c+y/c)-2+solve4(a+c,b,c));
	if(a+2*c<=x) ans=min(ans,2*(x/c+y/c)-3+solve5(a+2*c,b,c));
	if(b+2*c<=y) ans=min(ans,2*(x/c+y/c)-3+solve5(b+2*c,a,c));
	cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3632kb

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: 2ms
memory: 3568kb

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
12
6
4
6
4
2
4
4
4
3
4
4
4
4
4
4
4
4
4
4
14
7
5
4
6
4
2
4
4
4
4
3
4
4
4
4
4
4
4
4
16
8
6
4
6
6
4
2
4
4
4
4
4
3
4
4
4
4
4
4
18
9
6
5
4
6
6
4...

result:

wrong answer 84th numbers differ - expected: '3', found: '6'