結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー kyushu1996
提出日時 2022-10-26 20:29:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 96,768 KB
最終ジャッジ日時 2025-02-08 12:51:42
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 58
権限があれば一括ダウンロードができます

ソースコード

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);
    
    double t,x,a,y,b; cin>>t>>x>>a>>y>>b;
    double n,m,l,ans=20000000;

    // 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)+ceil(a/b)
        m=ceil(abs(t)/b)+ceil(a/b);
        for(int i=ceil(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