QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18375#2265. Short CodingAK_Dream#WA 3ms3856kbC++142.1kb2022-01-18 16:29:072022-05-04 18:15:08

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 18:15:08]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3856kb
  • [2022-01-18 16:29:07]
  • 提交

answer

#include <bits/stdc++.h>
#define N 15
using namespace std;

int n, m, sx, sy, tx, ty, a[N];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool vis[N][N][5][4];
char s[N][N];
char ans[][100] = {
    "",
    "LEFT", 
    "RIGHT", 
    "FORWARD", 
    "GOTO 1",
    "GOTO 2",
    "GOTO 3",
    "GOTO 4",
    "IF-OPEN 1",
    "IF-OPEN 2",
    "IF-OPEN 3",
    "IF-OPEN 4"
};

inline bool ok(int x, int y) {
    return 1 <= x && x <= n && 1 <= y && y <= m && s[x][y] != '#';
} 
bool check(int len) {
    memset(vis, 0, sizeof(vis));
    int x = sx, y = sy, pc = 1, d = 0;
    while (1) {
        if (pc > len || vis[x][y][pc][d]) return 0;
        if (x == tx && y == ty) return 1;
        vis[x][y][pc][d] = 1;
        int id = a[pc];
        if (id == 1) {
            d = (d+1)%4; 
            if (++pc == len+1) pc = 1;
        } else if (id == 2) {
            d = (d+3)%4; 
            if (++pc == len+1) pc = 1;
        } else if (id == 3) {
            int nx = x+dx[d], ny = y+dy[d];
            if (ok(nx, ny)) x = nx, y = ny;
            if (++pc == len+1) pc = 1;
        } else if (4 <= id && id <= 7) {
            pc = id-3;
        } else {
            int nx = x+dx[d], ny = y+dy[d];
            if (ok(nx, ny)) pc = id-7;
            else if (++pc == len+1) pc = 1;
        }
    }
}

void dfs(int l, int mx) {
    if (l == mx) {
        if (check(l)) {
            printf("%d\n", l);
            for (int i = 1; i <= l; i++) {
                printf("%s\n", ans[a[i]]);
            }
            exit(0);
        }
        return;
    } 
    for (int i = 1; i <= 11; i++) {
        a[l+1] = i; dfs(l+1, mx);    
    }
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%s", s[i]+1);
        for (int j = 1; j <= m; j++) {
            if (s[i][j] == 'S') sx = i, sy = j;
            else if (s[i][j] == 'G') tx = i, ty = j;
        }
    }
    dfs(0, 1); dfs(0, 2); dfs(0, 3); dfs(0, 4);
    printf(
    "LEFT\n"
    "IF-OPEN 5\n"
    "RIGHT\n"
    "GOTO 2\n"
    "FORWARD\n"
    );
    return 0;
}

詳細信息

Test #1:

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

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

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

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

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

input:

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

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

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

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

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

input:

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

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

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

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

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

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

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

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: 2ms
memory: 3696kb

input:

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

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

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

input:

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

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

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

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: 3780kb

input:

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

output:

4
FORWARD
RIGHT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #19:

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

input:

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

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

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

input:

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

output:

4
RIGHT
FORWARD
LEFT
IF-OPEN 2

result:

ok correct answer!

Test #21:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #22:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #23:

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

input:

2 4
...S
##G#

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #24:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #25:

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

input:

2 3
#S#
..G

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #26:

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

input:

2 4
#.S#
#G##

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #27:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #28:

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

input:

2 4
S.#.
#G##

output:

2
RIGHT
FORWARD

result:

ok correct answer!

Test #29:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #30:

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

input:

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

output:

2
RIGHT
FORWARD

result:

ok correct answer!

Test #31:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

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

input:

3 3
S..
##.
##G

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #33:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #34:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #35:

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

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #36:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #37:

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

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #38:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #39:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #40:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #41:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
LEFT

result:

ok correct answer!

Test #42:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #43:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #44:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #45:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #46:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #47:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #48:

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

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
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #50:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
IF-OPEN 2

result:

ok correct answer!

Test #51:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #52:

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

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #53:

score: -100
Wrong Answer
time: 1ms
memory: 3856kb

input:

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

output:

LEFT
IF-OPEN 5
RIGHT
GOTO 2
FORWARD

result:

wrong output format Expected integer, but "LEFT" found