結果

問題 No.331 CodeRunnerでやれ
ユーザー bal4ubal4u
提出日時 2019-08-15 22:50:38
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 4,741 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 27,704 KB
実行使用メモリ 93,344 KB
平均クエリ数 85.59
最終ジャッジ日時 2023-09-23 18:02:29
合計ジャッジ時間 10,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
23,316 KB
testcase_01 AC 145 ms
23,340 KB
testcase_02 AC 173 ms
23,308 KB
testcase_03 AC 172 ms
23,380 KB
testcase_04 AC 185 ms
23,568 KB
testcase_05 AC 174 ms
23,556 KB
testcase_06 AC 168 ms
23,784 KB
testcase_07 AC 208 ms
24,208 KB
testcase_08 AC 194 ms
23,788 KB
testcase_09 AC 253 ms
23,476 KB
testcase_10 AC 221 ms
24,184 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.331 CodeRunnerでやれ
// bal4u 2019.8.15

#include <stdio.h>
#include <stdlib.h>

#if 0
int H = 19, W = 17;
char map[25][25] = {
"#################",
"#>..............#",
"###############.#",
"#.............#.#",
"#.###########.#.#",
"#.#.........#.#.#",
"#.#.#######.#.#.#",
"#.#.#.....#.#.#.#",
"#.#.#.###.#.#.#.#",
"#.#.#.#...#.#.#.#",
"#.#.#.#.###.#.#.#",
"#.#.#.#.....#.#.#",
"#.#.#.#######.#.#",
"#.#.#.........#.#",
"#.#.###########.#",
"#.#.............#",
"#.###############",
"#...............#",
"###############.#",
};

int H = 19, W = 19;
char map[25][25] = {
"###################",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#^#.#.#",
"#####.#############"
};

int H = 20, W = 20;
char map[25][25] = {
"####################",
"#..........#.#...#.#",
"##..#..##.#....#...#",
"#.##.#...#.#.#..##.#",
"#......#.#..#.#..#..",
"#.#.#.#.#..#...#..##",
"#..#.....#...#..#.##",
"#.#..#.#..#.#.#....#",
"#..##...#.....#.##.#",
"#.#.###..####.#..#.#",
"#.#....#.......#..##",
"#..#.#..#.#.###..#.#",
"#.#..#.#..##...##..#",
"#..#..#..#...#...#.#",
"#.#..#.#...#..##...#",
"#.##.....#..##...#.#",
"#...#.#.#.#...#.#..#",
"##.#>#.#.#..##...#.#",
"#....#.....#...##..#",
"####################"
};

int H = 19, W = 19;
char map[25][25] = {
"###################",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"..#.#.#.#.#.#.#<#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.................#",
"###################"
};

int H = 19, W = 17;
char map[25][25] = {
"#################",
"#>..............#",
"###############.#",
"#.............#.#",
"#.###########.#.#",
"#.#.........#.#.#",
"#.#.#######.#.#.#",
"#.#.#.....#.#.#.#",
"#.#.#.###.#.#.#.#",
"#.#.#.#...#.#.#.#",
"#.#.#.#.###.#.#.#",
"#.#.#.#.....#.#.#",
"#.#.#.#######.#.#",
"#.#.#.........#.#",
"#.#.###########.#",
"#.#.............#",
"#.###############",
"#...............#",
"###############.#"
};
#endif

#define TEST 0
int H = 19, W = 19;
char map[25][25] = {
"###################",
"#.................#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#.#.#.#",
"#.#.#.#.#.#.#^#.#.#",
"#####.#############"
};

int r, c, dir, step;
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

void init() {
#if TEST
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) {
		if (map[r][c] == '^') { dir = 0; return; }
		if (map[r][c] == 'v') { dir = 2; return; }
		if (map[r][c] == '<') { dir = 3; return; }
		if (map[r][c] == '>') { dir = 1; return; }
	}
	printf("Panic!!! no initial (r,c)\n");
	exit(0);
#endif
}

void move(char *s, char ch) {
#if TEST
	int rr, cc;
	*(s+1) = 0;
	if (ch == 'L') {
		if (--dir < 0) dir += 4;
		rr = r + mv[dir][0], cc = c + mv[dir][1];
		*s = (map[rr][cc] != '#')? '1': '0';
	} else if (ch == 'R') {
		if (++dir == 4) dir -= 4;
		rr = r + mv[dir][0], cc = c + mv[dir][1];
		*s = (map[rr][cc] != '#')? '1': '0';
	} else if (ch == 'F') {
		rr = r + mv[dir][0], cc = c + mv[dir][1];
		if (rr < 0 || rr >= H || cc < 0 || cc >= W) *s = 'M';
		else {
			if (map[rr][cc] != '#') r = rr, c = cc, *s = '1';
			else *s = '0';
		}
	} else if (ch == 'B');
	else *s = (map[r][c] != '#')? '1': '0';

	printf("ch=%c, (%d,%d) dir=%d\n", ch, r,c,dir);
	if (++step > 5000) { printf("Time over\n"); exit(0); }
#endif
}

int action(char ch) {
	char s[20]; int d;
	while (1) {
#if TEST
		move(s, ch);
#else
		if (ch) {
			putchar(ch), putchar('\n');
			fflush(stdout);
		}
		scanf("%s", s);
#endif
		if (*s == 'M') {
#if TEST
			printf("OK steps=%d\n", step);
#endif
			exit(0);
		}
		if ((d = atoi(s)) < 20151224) break;
		ch = 'F';
	}
	return d;
}

int main()
{
	int d; char a;

	init();

	d = action(0);
	while (d) d = action('F');
	d = action('L');
	while (d) d = action('F');
	
	d = action('L');
	while (1) {
		if (d == 0) d = action('R');
		while (d == 0) d = action('L');
		while (d = action('F')) {
			d = action('R');
			if (d == 0) d = action('L');
		}
	}
	return 0;
}
0