結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー kyushu1996
提出日時 2022-10-26 22:37:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 97,196 KB
最終ジャッジ日時 2025-02-08 13:03:28
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>
#define ll long long
#define endl '\n'
using namespace std;
// category : 

int main() {
    ios_base::sync_with_stdio(false);
    
    ll t,x,a,y,b; cin>>t>>x>>a>>y>>b;
    ll n,m,l,ans=20000000ll*20000000ll;

    // min of x*n+y*m+l
    // when a*n-b*m+l = t

    if(t>0){
        // m=0 ~ (t-floor(t/a)*a) + floor(t/a)*x
        m=(t-floor(t/a)*a) + floor(t/a)*x;
        for(int i=0;i<=m;i++){
            n=floor((t+b*i)/a);
            l=t-a*n+b*i;
            ans=min(n*x+i*y+l,ans);
        }
    }
    else{
        // m=ceil(|t|/b) ~ ceil(|t|/b)+ floor((ceil(|t|/b)*b-|t|)/y)
        m=ceil(double(abs(t))/b)+ floor((ceil(double(abs(t))/b)*b-abs(t))/y);
        for(int i=ceil(double(abs(t))/b);i<=m;i++){
            n=floor((b*i-abs(t))/a);
            l=b*i-abs(t)-a*n;
            ans=min(n*x+i*y+l,ans);
        }

    }
    cout<<ans<<endl;

	return 0;
}
0