結果
| 問題 |
No.126 2基のエレベータ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-12 04:25:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 929 bytes |
| コンパイル時間 | 1,828 ms |
| コンパイル使用メモリ | 192,984 KB |
| 最終ジャッジ日時 | 2025-01-15 06:50:12 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
/*
エレベータのかご内は、そのエレベータが行くことができれば任意の階のボタンを押して移動することができる。
これか〜〜〜〜
*/
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a,b,s; cin >> a >> b >> s;
int res=1e9;
{ // 上を押した場合
if(abs(a-s)<=abs(b-s)){ // Aが来る
res=min(res,abs(a-s)+s);
}
else{ // Bが来る
if(1){
res=min(res,abs(b-s)+abs(a-s)+a+(a==0?1:0));
}
}
}
{ // 下を押した場合
if(s==1){
res=min(res,abs(a-s)+1);
}
else if(abs(a-s)<=abs(b-s)){ // Aが来る
res=min(res,abs(a-s)+s);
}
else{ // Bが来る 1階に向かう
res=min(res,abs(b-s)+s-1+abs(a-1)+1);
if(1){ // A階に向かう場合忘れてた。。。
res=min(res,abs(b-s)+abs(s-a)+a+(a==0?1:0));
}
}
}
cout << res << endl;
}