QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92945#5259. Skills in PillsRedcrownWA 2ms3648kbC++171.4kb2023-03-31 09:04:532023-03-31 09:04:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 09:04:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3648kb
  • [2023-03-31 09:04:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e6 + 5;

ll n,a,b,sum[MAXN],sum1[MAXN],sum2[MAXN];
int solve(ll sum[], ll nowa, ll nowb)
{
	ll i;
	for(i=1;i<=n;i++)
	{
		if(nowa == a)
		{
			sum[i] ++; nowa = 0;
		}
		if(nowb == b)
		{
			if(sum[i]) return i-1;
			sum[i] ++; nowb = 0;
		}
		nowa ++; nowb ++; sum[i] += sum[i-1];
		//printf("%lld nowans: %lld %lld %lld\n",i,sum[i],nowa,nowb);
	}
	return n;
}

int main()
{
	ll l,l1,l2,d,ans,nowl1,nowl2,p,pls;
	scanf("%lld%lld%lld",&a,&b,&n);
	if(__gcd(a,b) > 1)
	{
		d = a*b/__gcd(a,b)-1;
		ans = d/a+d/b + 2;
		d ++;
		ans += min((n+1-d)/a+(n-d)/b,(n+1-d)/b+(n-d)/a);
		printf("%lld\n",ans);
		return 0;
	}
	l = solve(sum,1,1);
	if(l >= n)
	{
		printf("%lld\n",sum[n]); return 0;
	}
	ans = n;
	d = n-l+1;
	l1 = solve(sum1,a,b-1)-1;
	l2 = solve(sum2,a-1,b)-1;
	//printf("%lld %lld %lld %lld %lld %lld goin!\n",d,l1,l2,sum1[l1],sum2[l2],sum[l]);
	nowl1 = d/l1; nowl2 = 0;
	while(nowl1 >= 0)
	{
		while(l1*nowl1+l2*nowl2+l2 <= d) nowl2 ++;
		p = d-l1*nowl1-l2*nowl2;
		//printf("now: %lld %lld %lld %lld %lld %lld\n",d,nowl1,nowl2,l1,l2,p);
		if(p > 1)
		{
			pls = n;
			if(p <= l1+1) pls = min(pls,sum1[p]);
			if(p <= l2+1) pls = min(pls,sum2[p]);
		}
		else pls = 0;
		//printf("pls: %lld\n",pls);
		ans = min(ans,sum[l]+sum1[l1]*nowl1+sum2[l2]*nowl2+pls);
		nowl1 --;
	}
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

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

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3620kb

input:

10 8 13

output:

4

result:

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