結果

問題 No.48 ロボットの操縦
ユーザー ty70
提出日時 2016-11-01 12:38:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 158,152 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 00:41:48
合計ジャッジ時間 1,934 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int X, Y, L; cin >> X >> Y >> L;

	int quadrant = 0;
	if (X > 0 && Y >= 0){
		quadrant = 1;
	}else
	if (X <= 0 && Y > 0){
		quadrant = 2;
	}else
	if (X < 0 && Y <= 0){
		quadrant = 3;
	}else
	if (X >= 0 && Y < 0){
		quadrant = 4;
	} // end if

	int res = 0;
	switch(quadrant){
		case 1:
		case 2:
			res += (abs(Y) + L - 1) / L;	// Y 方向に進む
			res += (X != 0);			// 一回ターンする?
			res += (abs(X) + L - 1) / L; 	// X 方向に進む
			break;
		case 3:
		case 4:
			++res;					// 一回ターン
			res += (abs(X) + L - 1) / L; 	// X 方向に進む
			res += (Y != 0);			// 一回ターンする?
			res += (abs(Y) + L - 1) / L;	// Y 方向に進む
			break;
		default:
			// 原点の時にはここに来る
			break;
	} // end switch
	
	cout << res << endl;

	return 0;
}
0