結果
| 問題 | 
                            No.126 2基のエレベータ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-07-31 02:33:32 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,109 bytes | 
| コンパイル時間 | 1,498 ms | 
| コンパイル使用メモリ | 166,496 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-10 18:30:39 | 
| 合計ジャッジ時間 | 2,429 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#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(s==1)
    {
        //必ずAが来る
        if(a==0) ans=2;
        else ans=a;
    }
    else
    {
        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;
}