QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90465#5259. Skills in Pillsysghwzp#WA 2ms3364kbC++14897b2023-03-23 11:14:312023-03-23 11:14:32

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-23 11:14:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3364kb
  • [2023-03-23 11:14:31]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
using namespace std;
const int N=1000005;
ll a,b,n;
ll f[N];
ll lcm(ll a,ll b){
	return a*b/__gcd(a,b);
}
int sol(int x,int zs,int n){
	n-=x;
	return min((n+1)/a+n/b,n/a+(n+1)/b)+zs;
}
int main(){
	cin>>a>>b>>n;
	For(i,1,n)f[i]=1e9;
	if(lcm(a,b)>n){
		cout<<n/a+n/b<<endl;
	}else{
		if(__gcd(a,b)!=1){
			cout<<sol(lcm(a,b),a+b,n)<<endl; return 0;
		}
		f[lcm(a,b)]=a+b;
		ll f1,f2,g1,g2;
		for(int i=0;i<a;i++)if(i*b%a==1){
			f1=i*b-1; f2=i+i*b/a;
		}
		for(int i=0;i<b;i++)if(i*a%b==1){
			g1=i*a-1; g2=i+i*a/b;
		}
		ll ans=1e9;
		for(int i=1;i<=n;i++){
			if(i+f1<=n)f[i+f1]=min(f[i+f1],f[i]+f2); else ans=min(ans,f[i]+(n-i)/a+(n-i+1)/b);
			if(i+g1<=n)f[i+g1]=min(f[i+g1],f[i]+g2); else ans=min(ans,f[i]+(n-i)/b+(n-i+1)/a);
		}
		cout<<ans<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3364kb

input:

3 9 20

output:

16

result:

wrong answer 1st lines differ - expected: '8', found: '16'