QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#17902#2265. Short CodingQingyuWA 4ms3848kbC++202.5kb2022-01-15 09:30:082022-05-04 16:17:37

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 16:17:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3848kb
  • [2022-01-15 09:30:08]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 12;

int sx = -1, sy = -1, tx = -1, ty = -1;
int n, m, a[N][N];
int op[N];

// 1: GOTO 1
// 2: GOTO 2
// 3: GOTO 3
// 4: GOTO 4
// 5: IF-OPEN 1
// 6: IF-OPEN 2
// 7: IF-OPEN 3
// 8: IF-OPEN 4
// 9: FORWARD
// 10: LEFT
// 11: RIGHT

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int vis[N][N][5][5], curt;

inline bool simulate(int L) {
	int x = sx, y = sy, d = 0, pc = 1;
	++curt;
	while (x != tx || y != ty) {
		int c = op[pc];
		if (vis[x][y][d][pc] == curt) return false;
		vis[x][y][d][pc] = curt;
		if (c <= 4) {
			if (L < c) return false;
			pc = c;
		}
		else if (c <= 8) {
			if (L < c - 4) return false;
			int nx = x + dx[d], ny = y + dy[d];
			if (1 <= nx && nx <= n && 1 <= ny && ny <= m && !a[nx][ny]) {
				pc = c - 4;
			}
			else {
				++pc;
			}
		}
		else if (c == 9) {
			int nx = x + dx[d], ny = y + dy[d];
			if (1 <= nx && nx <= n && 1 <= ny && ny <= m && !a[nx][ny]) {
				x = nx, y = ny;
			}
			++pc;
		}
		else if (c == 10) {
			d = (d + 1) & 3;
			++pc;
		}
		else if (c == 11) {
			d = (d + 3) & 3;
			++pc;
		}
		else throw;
		if (pc == L + 1) pc = 1;
	}
	return true;
}

void dfs(int i, int L){
	if (i == L) {
		if (simulate(L)) {
			printf("%d\n", L);
			for (int i = 1; i <= L; ++i) {
				if (op[i] == 1) puts("GOTO 1");
				else if (op[i] == 2) puts("GOTO 2");
				else if (op[i] == 3) puts("GOTO 3");
				else if (op[i] == 4) puts("GOTO 4");
				else if (op[i] == 5) puts("IF-OPEN 1");
				else if (op[i] == 6) puts("IF-OPEN 2");
				else if (op[i] == 7) puts("IF-OPEN 3");
				else if (op[i] == 8) puts("IF-OPEN 4");
				else if (op[i] == 9) puts("FORWARD");
				else if (op[i] == 10) puts("LEFT");
				else if (op[i] == 11) puts("RIGHT");
				else throw;
			}
			exit(0);
		}
	}
	else {
		for (int j = 1; j <= 11; ++j) {
			op[i + 1] = j;
			dfs(i + 1, L);
			op[i + 1] = -1;
		}
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	std::cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		std::string s;
		std::cin >> s;
		for (int j = 0; j < m; ++j)
			if (s[j] == 'S') {
				sx = i, sy = j + 1;
			}
			else if (s[j] == 'G') {
				tx = i, ty = j + 1;
			}
			else if (s[j] == '#') {
				a[i][j + 1] = 1;
			}
	}
	for (int len = 1; len <= 4; ++len) {
		dfs(0, len);
	}
	puts("5");
	puts("LEFT");
	puts("FORWARD");
	puts("RIGHT");
	puts("FORWARD");
	puts("IF-OPEN 4");
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3712kb

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

3 6
##S..#
#..##.
.G..#.

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

3 7
....S##
.#.#...
##.#.G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

score: 0
Accepted
time: 3ms
memory: 3784kb

input:

4 8
...S.#.#
##..#.#.
###...#.
#.#.#G.#

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

3 5
.S#..
.....
..#G.

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

score: 0
Accepted
time: 3ms
memory: 3704kb

input:

10 10
.....S#...
...#......
....##....
.#.....#..
....#.....
..#.......
...#......
..........
.#...#....
G.#..#...#

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

score: 0
Accepted
time: 3ms
memory: 3756kb

input:

7 9
.##S.#..#
.........
.........
...#...##
###..####
........#
.....##G#

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

score: 0
Accepted
time: 3ms
memory: 3732kb

input:

3 9
..#.#.#S#
#...#...#
.G....#.#

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

score: 0
Accepted
time: 3ms
memory: 3788kb

input:

4 5
#S...
..#..
.#..#
.#.G#

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

score: 0
Accepted
time: 1ms
memory: 3704kb

input:

6 8
..S..#.#
...#...#
....#..#
#.#.##..
.......#
.#..#G.#

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

score: 0
Accepted
time: 3ms
memory: 3680kb

input:

9 10
S.........
.#..#....#
........#.
..........
.....#.#..
.#...#....
#..#.##.#.
..#..#...#
..#.#....G

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

10 4
#.S.
.#.#
##.#
##..
.#..
#...
#.##
..#.
.#..
G.##

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

score: 0
Accepted
time: 3ms
memory: 3704kb

input:

9 9
#..#...S#
.#...##.#
.....##..
..#..#...
..#..#..#
.#..#.#.#
.###.....
..#.#.##.
G#....#.#

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #14:

score: 0
Accepted
time: 3ms
memory: 3792kb

input:

7 3
.S#
#..
..#
...
..#
.#.
.G.

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #15:

score: 0
Accepted
time: 3ms
memory: 3748kb

input:

6 6
..#S..
#.#.#.
.....#
#.#...
..#...
..G##.

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

score: 0
Accepted
time: 3ms
memory: 3652kb

input:

6 8
....#S..
......#.
..##..#.
###.#.##
..#...#.
##.G#..#

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

10 8
#..S.###
.#....##
.#......
....#.#.
#...#..#
........
....#.##
...#.###
.#.#...#
.#...G.#

output:

4
FORWARD
LEFT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #18:

score: 0
Accepted
time: 3ms
memory: 3716kb

input:

7 6
...##S
#.....
....#.
...#.#
....#.
#.....
.....G

output:

4
FORWARD
RIGHT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #19:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

4 8
.##..S..
#.###..#
.#...#..
...#G...

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

score: 0
Accepted
time: 3ms
memory: 3712kb

input:

3 10
##.......S
####.####.
...#..G##.

output:

4
RIGHT
FORWARD
LEFT
IF-OPEN 2

result:

ok correct answer!

Test #21:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 7
.#S.###
.#.G..#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #22:

score: 0
Accepted
time: 3ms
memory: 3696kb

input:

2 7
.S#.#.#
G#.##.#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #23:

score: 0
Accepted
time: 3ms
memory: 3688kb

input:

2 4
...S
##G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #24:

score: 0
Accepted
time: 3ms
memory: 3580kb

input:

2 7
S......
.G.....

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #25:

score: 0
Accepted
time: 3ms
memory: 3768kb

input:

2 3
#S#
..G

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #26:

score: 0
Accepted
time: 3ms
memory: 3836kb

input:

2 4
#.S#
#G##

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #27:

score: 0
Accepted
time: 2ms
memory: 3780kb

input:

3 6
.#S###
#....#
#G.#..

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #28:

score: 0
Accepted
time: 2ms
memory: 3836kb

input:

2 4
S.#.
#G##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #29:

score: 0
Accepted
time: 3ms
memory: 3580kb

input:

2 5
##..S
...G.

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #30:

score: 0
Accepted
time: 3ms
memory: 3704kb

input:

2 9
#S###....
G..##..##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #31:

score: 0
Accepted
time: 2ms
memory: 3732kb

input:

6 10
....S...##
.#...#....
..........
.#.#...#..
...#.##...
.G#...#...

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

3 3
S..
##.
##G

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #33:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

5 5
..S..
.##..
.####
..#..
G.#.#

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #34:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

4 6
S#....
....#.
#.....
#...G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #35:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

3 6
.#..S#
..#..#
.##G.#

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #36:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

4 3
..S
.#.
..#
G..

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #37:

score: 0
Accepted
time: 3ms
memory: 3740kb

input:

5 3
S..
##.
...
...
.G.

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #38:

score: 0
Accepted
time: 3ms
memory: 3848kb

input:

8 2
.S
..
..
..
..
..
.#
G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #39:

score: 0
Accepted
time: 1ms
memory: 3772kb

input:

3 7
...#..S
#.#....
....G..

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #40:

score: 0
Accepted
time: 3ms
memory: 3784kb

input:

3 9
#......S.
...#.#...
.G.#.#...

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #41:

score: 0
Accepted
time: 3ms
memory: 3780kb

input:

2 9
.##..S...
##..##G.#

output:

4
IF-OPEN 3
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #42:

score: 0
Accepted
time: 3ms
memory: 3712kb

input:

4 6
S..#.#
..#...
......
..#G#.

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #43:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

4 9
#..##S..#
##..#...#
#.......#
####.#G##

output:

4
IF-OPEN 3
LEFT
LEFT
FORWARD

result:

ok correct answer!

Test #44:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

3 8
....S...
.....#..
..#G#...

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #45:

score: 0
Accepted
time: 3ms
memory: 3752kb

input:

4 9
.#.S#####
..#.###..
.#....#.#
.####.G.#

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #46:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

4 3
..S
...
...
#G#

output:

4
IF-OPEN 3
LEFT
LEFT
FORWARD

result:

ok correct answer!

Test #47:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

2 7
#...S..
..#G##.

output:

4
IF-OPEN 3
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #48:

score: 0
Accepted
time: 4ms
memory: 3712kb

input:

5 6
...S..
...#..
...#..
...#.#
#G..#.

output:

4
RIGHT
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #49:

score: 0
Accepted
time: 3ms
memory: 3792kb

input:

4 8
.#...#.S
..###...
........
....G..#

output:

4
FORWARD
IF-OPEN 4
LEFT
LEFT

result:

ok correct answer!

Test #50:

score: 0
Accepted
time: 3ms
memory: 3720kb

input:

3 4
#S..
##..
.#G#

output:

4
IF-OPEN 3
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #51:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

4 6
#.S.#.
#..#..
..#...
..G##.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #52:

score: 0
Accepted
time: 3ms
memory: 3708kb

input:

4 5
#..S.
#.#..
..#..
G#..#

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #53:

score: -100
Wrong Answer
time: 2ms
memory: 3520kb

input:

5 5
#.#S#
#...#
##.##
##..#
.##.G

output:

5
LEFT
FORWARD
RIGHT
FORWARD
IF-OPEN 4

result:

wrong answer your program is not correct.