QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102582 | #5259. Skills in Pills | csw_ccc# | WA | 8ms | 11484kb | C++14 | 1.5kb | 2023-05-03 14:50:49 | 2023-05-03 14:51:15 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct point{
int x,y;
};
const int mxn=1000010;
int inf;
int i,j,k;
int x,y,z,xx,xy,xz,yx,yy,yz;
point px,py,pz;
int m,n,p;
int ma,mb;
int f[mxn],g[mxn];
int ans;
int gcd(int x,int y){
int z;
while(y){
x%=y;
z=x;
x=y;
y=z;
}
return x;
}
int lcm(int x,int y){
return x/gcd(x,y)*y;
}
point sol(int a,int b,int c){
if(b==0){
return (point){c/a,0};
}
if(a==0){
return (point){0,c/b};
}
point px=sol(b,a%b,c);
return (point){px.y,px.x-a/b*px.y};
}
int main(){
scanf("%d%d%d",&ma,&mb,&n);
memset(f,0x3f,sizeof(f));
memset(g,0x3f,sizeof(g));
ans=inf=f[0];
if(gcd(ma,mb)!=1){
ans=min(n/ma+(n+1)/mb,(n+1)/ma+n/mb);
printf("%d\n",ans);
return 0;
}
x=lcm(ma,mb);
f[x]=x/ma+x/mb;
g[x]=f[x];
f[0]=g[0]=0;
for(i=1;i<=n;i++){
px=sol(-ma,mb,1);
x=(px.x%mb+mb)%mb*ma;
y=i+x;
if(y<=n){
z=f[i]+x/ma+(x+1)/mb;
f[y]=min(f[y],z);
g[y]=min(g[y],z);
}else{
ans=min(ans,f[i]+(n-i)/ma+(n-i+1)/mb);
}
px=sol(-mb,ma,1);
x=(px.x%ma+ma)%ma*mb;
y=i+x;
if(y<=n){
z=g[i]+(x+1)/ma+x/mb;
f[y]=min(f[y],z);
g[y]=min(g[y],z);
}else{
ans=min(ans,g[i]+(n-i+1)/ma+(n-i)/mb);
}
}
/*for(i=0;i<=n;i++){
x=f[i]+(n-i)/ma+(n-i+1)/mb;
y=g[i]+(n-i+1)/ma+(n-i)/mb;
ans=min(ans,min(x,y));
//if(f[i]<inf||g[i]<inf)printf("<>%d %d %d\n",i,f[i],g[i]);
}*/
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11384kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11316kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 8ms
memory: 11484kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 7ms
memory: 11384kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11392kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: -100
Wrong Answer
time: 3ms
memory: 11328kb
input:
2 3 5
output:
1061109567
result:
wrong answer 1st lines differ - expected: '3', found: '1061109567'