結果

問題 No.126 2基のエレベータ
ユーザー imulan
提出日時 2016-07-31 02:31:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 165,144 KB
実行使用メモリ 6,816 KB
最終ジャッジ日時 2024-11-06 21:26:26
合計ジャッジ時間 2,399 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int a,b,s;
    cin >>a >>b >>s;

    int ans=0;
    if(abs(a-s)>abs(b-s))
    {//現在のフロアでボタンを押すとBが来る時
        if(a>0)
        {
            //Aのあるフロアまで移動してから地下へ
            ans=abs(b-s)+abs(s-a)+a;
            //とにかくbで1階まで行ってからAを呼ぶ
            ans=min(ans, abs(b-s)+s-1+a);
        }
        else ans=abs(b-s)+s-1+2;
    }
    else
    {//現在のフロアでボタンを押すとAが来る時
        //そのまま移動
        ans=abs(a-s)+s;
    }
    cout << ans << endl;
    return 0;
}
0