QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90465 | #5259. Skills in Pills | ysghwzp# | WA | 2ms | 3364kb | C++14 | 897b | 2023-03-23 11:14:31 | 2023-03-23 11:14:32 |
Judging History
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;
}
}
詳細信息
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'