QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#308114#8111. Coachesvme50WA 1ms3792kbC++171.1kb2024-01-19 16:01:042024-01-19 16:01:06

Judging History

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

  • [2024-01-19 16:01:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3792kb
  • [2024-01-19 16:01:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd __gcd
int T,a,b;ll n,d,t,ans;
void W(ll &x,ll y) {x=max(x,y);}
ll dv(ll x,ll y) {return x>0?(x-1)/y+1:0;}
int find1(int x,int r,int y,int p,int w1,int w2)
{
	if(r<=y) return 0;if(x>=p) x-=p;
	if(!x) return -1;int d=(p-r-1)/x,t;r+=d*(x+1)-p;
	t=find1(x-p%x,r,y,x,(p-1)/x*w1+w2,((p-1)/x-1)*w1+w2);
	return ~t?t+d*w1+w2:-1;
}
int find(int x,int r,int y,int p)
{x%=p;r%=p;return find1(p-x,p-r-1,p-y-1,p,1,1);}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld %d %d",&n,&a,&b);
		ans=n-n/a-n/b;d=1ll*a/gcd(a,b)*b;
		t=find(a,n%a,n%b,b);
		if(~t) t=t*a+n%a,W(ans,n-n/a-n/b+dv(n-t,d)*2);
		t=find(b,n%b,n%a,a);
		if(~t) t=t*b+n%b,W(ans,n-n/a-n/b+dv(n-t,d)*2);
		t=find(a,0,n%b,b);
		if(~t) t*=a,W(ans,n-n/a-n/b+dv(n-t,d)*2-1);
		t=find(b,0,n%a,a);
		if(~t) t*=b,W(ans,n-n/a-n/b+dv(n-t,d)*2-1);
		t=find(a,n%a,0,b);
		if(~t) t=t*a+n%a,W(ans,n-n/a-n/b+dv(n-t,d)*2-1);
		t=find(b,n%b,0,a);
		if(~t) t=t*b+n%b,W(ans,n-n/a-n/b+dv(n-t,d)*2-1);
		printf("%lld\n",ans);
	}return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

input:

2
5 2 3
10 7 2

output:

3
6

result:

ok 2 number(s): "3 6"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3792kb

input:

1728
7 6 3
10 12 1
6 2 7
8 4 10
11 10 5
1 6 8
3 3 5
9 2 6
11 1 5
1 1 8
7 3 6
6 10 9
2 1 7
3 4 7
8 3 4
4 5 9
9 4 3
6 2 8
11 4 1
6 8 4
11 1 8
9 11 2
9 6 1
5 3 8
7 1 8
7 11 12
3 9 1
2 12 6
7 2 6
5 11 10
9 5 3
3 6 2
7 5 5
12 4 3
7 8 2
8 11 11
10 1 10
5 1 7
9 1 7
8 1 6
8 4 6
5 5 11
12 3 7
3 6 8
6 3 11
6 ...

output:

6
2
5
8
10
1
3
7
3
1
6
6
2
3
6
4
6
5
4
6
3
7
3
5
2
7
2
2
5
5
7
3
7
7
6
8
1
2
3
3
7
5
9
3
6
5
11
3
1
1
12
3
7
1
5
6
12
2
10
2
9
5
1
2
10
6
3
12
1
12
10
6
1
7
2
5
10
7
11
9
2
3
1
7
9
8
2
5
3
3
10
1
9
11
2
8
8
8
7
9
3
2
2
4
2
3
3
9
4
6
8
2
12
6
3
10
2
1
9
12
6
1
9
11
1
6
2
3
12
7
7
6
9
11
10
1
2
6
2
4
...

result:

wrong answer 2nd numbers differ - expected: '1', found: '2'