結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー kuraraberu
提出日時 2022-10-14 22:25:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 165,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 15:44:23
合計ジャッジ時間 3,375 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 WA * 30
権限があれば一括ダウンロードができます

ソースコード

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;
            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;
            cout<<min(mae,ushiro)<<endl;
            return 0;
        }
    }
    
}
0