QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#731198 | #5259. Skills in Pills | jay248 | TL | 0ms | 0kb | C++14 | 1.5kb | 2024-11-10 00:38:23 | 2024-11-10 00:38:24 |
answer
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int x, int y){
int tmp;
if(x<y){
tmp = x;
x = y;
y = tmp;
}
while(y>0){
tmp = y;
y = x%y;
x = y;
}
return x;
}
int main(){
int k, j, n;
int ans;
int a[1000005];
int b[1000005];
cin>>k>>j>>n;
int cnt1=0;
int cnt2=0;
if(gcd(k, j)>1){
ans = fmin(n/k + (n+1)/j, (n+1)/k + n/j);
}
else{
int x, y;
x=1;
while(true){
if((k*x-1)%j==0) break;
x++;
}
for(int i=1; i<=k*x-1; i++){
a[i] = (i+1)/k + i/j;
}
y=1;
while(true){
if((j*y-1)%k==0) break;
y++;
}
for(int i=1; i<=j*y-1; i++){
b[i] = (i+1)/j + i/k;
}
if(k*x > y*j){
for(int i=y*j; i<k*x; i++){
b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
}
for(int i=k*x; i<=n; i++){
a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
}
}
else{
for(int i=k*x; i<y*j; i++){
a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
}
for(int i=y*j; i<=n; i++){
a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
}
}
ans = k+j+fmin(a[n-j*k], b[n-j*k]);
}
cout<<ans<<'\n';
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 9 20