結果

問題 No.331 CodeRunnerでやれ
ユーザー E31415926E31415926
提出日時 2016-05-28 18:03:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,262 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 54,000 KB
実行使用メモリ 24,420 KB
平均クエリ数 70.00
最終ジャッジ日時 2023-09-23 10:42:30
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
24,396 KB
testcase_01 AC 157 ms
23,664 KB
testcase_02 AC 180 ms
23,608 KB
testcase_03 AC 170 ms
23,536 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 184 ms
23,484 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 265 ms
23,488 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
#define	UNKNOWN	0
#define	ISEMPTY	1
#define ISWALL	2
#define UNPASSED 3
#define UP		0
#define RIGHT	1
#define DOWN	2
#define LEFT	3

int dirtbl[4][2] = { {0,-1},{1,0},{0,1},{-1,0} };

int main()
{
	//初期位置を(19,19)上向きとする
	int map[39][39]{ {0} }, x = 19, y = 19,
		dx = 0, dy = -1, n, i, xtmp, ytmp, direction = UP,
		dirtmp;
	map[19][19] = ISEMPTY;

	while (1) {
		cin >> n;
		if (cin.fail()) { return 0; }
		if (n == 20151224) {
			cout << "F" << endl << flush;
			x += dx; y += dy;
			continue;
		}
		xtmp = x + dx; ytmp = y + dy;
		for (i = 0; i < n; ++i) {
			if (map[xtmp][ytmp] == UNKNOWN) {
				map[xtmp][ytmp] = UNPASSED;
			}
			xtmp += dx; ytmp += dy;
		}
		map[x + (n + 1) * dx][y + (n + 1) * dy] = ISWALL;

		//右?
		dirtmp = (direction + 1) % 4;
		xtmp = dirtbl[dirtmp][0]; ytmp = dirtbl[dirtmp][1];
		if (map[x + xtmp][y + ytmp] == UNKNOWN) {
			cout << "R" << endl << flush;
			direction = dirtmp;
			dx = xtmp; dy = ytmp;
			continue;
		}

		//左?
		dirtmp = (direction + 3) % 4;
		xtmp = dirtbl[dirtmp][0]; ytmp = dirtbl[dirtmp][1];
		if (map[x + xtmp][y + ytmp] == UNKNOWN) {
			cout << "L" << endl << flush;
			direction = dirtmp;
			dx = xtmp; dy = ytmp;
			continue;
		}

		//逆?
		dirtmp = (direction + 2) % 4;
		xtmp = dirtbl[dirtmp][0]; ytmp = dirtbl[dirtmp][1];
		if (map[x + xtmp][y + ytmp] == UNKNOWN) {
			cout << "R" <<endl << flush;
			direction = (direction + 1) % 4;
			dx = dirtbl[direction][0]; dy = dirtbl[direction][1];
			continue;
		}

		//前?
		if (map[x + dx][y + dy] == UNPASSED) {
			cout << "F" << endl << flush;
			x += dx; y += dy;
			map[x][y] = ISEMPTY;
			continue;
		}

		//壁?
		if (map[x + dx][y + dy] == ISWALL) {
			dirtmp = (direction + 3) % 4;
			xtmp = dirtbl[dirtmp][0]; ytmp = dirtbl[dirtmp][1];
			if (map[x + xtmp][y + ytmp] == UNPASSED) {
				cout << "L" << endl << flush;
				direction = dirtmp;
				dx = xtmp; dy = ytmp;
				continue;
			}
			else {
				cout << "R" << endl << flush;
				direction = (direction + 1) % 4;
				dx = dirtbl[direction][0]; dy = dirtbl[direction][1];
				continue;
			}
		}
		//それ以外
		cout << "F" << "その他" << endl << flush;
		x += dx; y += dy;
		map[x][y] = ISEMPTY;
	}
	return 0;
}
0