結果

問題 No.126 2基のエレベータ
ユーザー ramia777ramia777
提出日時 2022-06-14 11:19:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,078 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 96,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 04:00:21
合計ジャッジ時間 2,044 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicodr
// No.126



//二次元可変配列
//vector <vector <int>> mass;
//vector <vector <int>> memo;
//vector <int> memo;


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>//list
#include <queue> //queue
#include <set> //連想コンテナ(要素が自動でソートされる)、要素1つ(Key)、keyの重複ない、O(logN)
#include <map> //連想コンテナ(要素が自動でソートされる)、要素2つ(Key,data)、keyの重複ない、dataは重複あり、O(logN)
#include <unordered_set> //hash、O(1)
#include <unordered_map> //hash、O(1)
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <climits>
//#include <bits/stdc++.h>

using namespace std;

#define FOR(x,to) for(x=0;x<to;x++)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FMAX(a,b)  ((a)>(b)?(a):(b))
#define FMIN(a,b)  ((a)<(b)?(a):(b))
#define FCEIL(a,b)  ((a)+(b)-1)/(b)

typedef unsigned long long ULL;
typedef signed long long SLL;


queue<int> _queue;


int A, B, S;

int main()
{
	cin >> A;
	cin >> B;
	cin >> S;


	int a_only = abs(S - A) + S;


	//1階でボタンを押したらAだけで移動
	if (S == 1)
	{
		cout << a_only;
		return 0;

	}

	//Sとの距離がAが近い or 同じならAだけで移動
	if (abs(S - A) <= abs(S - B))
	{
		cout << a_only;
	}
	else
	{
		//Sとの距離がBが近い場合はBを使うことになる
		int d = 0;

		//まずBはSのところまで絶対動く
		d = abs(B - S);

		//Aはどのみち1階まではいく必要があるのでS地点からのBの移動量がポイントになる
		//BはAのところまでいくか、それとも1階までいくか、どちらか近いほうに行く
		if (abs(A - S) > S-1)
		{
			//cout << "down to 1th." << endl;
			d += S-1; //1階へ
		}
		else
		{
			//cout << "move to A." << endl;
			d += abs(A - S);//Aのところへ、ただし1階まで

		}


		d += A;

		//もしAが地下にいる場合はAは上がって下がる
		if (A == 0)
			d += 2;

		cout << d;
	}
	
	return 0;

}

0