結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー kuraraberu
提出日時 2022-10-14 22:51:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,837 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 167,784 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 16:31:27
合計ジャッジ時間 3,361 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

template<typename T>bool chmax(T &a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a, const T& b){if(a>b){a=b;return true;}return false;}

int main(){
    int t;cin>>t;
    int x,a;cin>>x>>a;
    int y,b;cin>>y>>b;
    if(t<0){
        // t=-t;
        swap(x,y);
        swap(a,b);
    }
    if(t>0){
        int w=t/a;
        int ama=t%a;
        if(ama==0){
            cout<<x*w<<endl;
            return 0;
        }
        else{
            // int ne=w+1;
            int mae=x*w+t%a;
            // cout<<mae<<endl;
            int ushiro=x*(t+b)/a+y+(t+b)%a;
            // cout<<ushiro<<endl;
            int cun=0;
            int ans=1e9;
            while((t+cun*b)%a!=0){
                ans=min(ans,((t+cun*b)/a)*x+y*cun+((t+cun*b)%a));
                // cout<<ans<<endl;
                cun++;
                if(cun>20)break;
            }
            mae=min(ans,mae);
            cout<<min(mae,ushiro)<<endl;
            return 0;
        }
    }
    else{
        t=-t;
        int w=t/a;
        int ama=t%a;
        if(ama==0){
            cout<<x*w<<endl;
            return 0;
        }
        else{
            int ne=w+1;
            int mae=x*ne+(ne*a)-t;
            // cout<<mae<<endl;
            int ushiro=x*(t+b)/a+y+(t+b)%a;
            // cout<<ushiro<<endl;
            int cun=0;
            int ans=1e9;
            while((t+cun*b)%a!=0){
                ans=min(ans,((t+cun*b)/a+1)*x+cun*y+((t+cun*b)/a+1)*a-t);
                // cout<<ans<<endl;
                cun++;
                if(cun>20)break;
            }
            mae=min(ans,mae);
            cout<<min(mae,ushiro)<<endl;
            return 0;
        }
    }
    
}
0