QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#18207 | #2265. Short Coding | namelessgugugu# | AC ✓ | 5ms | 3280kb | C++14 | 2.4kb | 2022-01-16 19:36:34 | 2022-05-04 17:20:40 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
const int N = 13;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int n, m;
char s[N][N];
bool f[N][N][4][5];
/*
1 : Left
2 : Right
3 : Forward
4 ~ 7 : Goto i - 3
8 ~ 12 : If-open i - 7
*/
std::vector<int> ans;
std::vector<int> now;
bool check(int x, int y, int d, int k)
{
if(x == 0)
puts(">");
if(f[x][y][d][k])
return 0;
f[x][y][d][k] = 1;
if(s[x][y] == 'G')
return 1;
if(now[k] == 1)
return check(x, y, (d + 1) % 4, (k + 1) % (signed)now.size());
else if(now[k] == 2)
return check(x, y, (d + 3) % 4, (k + 1) % (signed)now.size());
else if(now[k] == 3)
{
int nx = x + dx[d], ny = y + dy[d];
if(nx < 1 || nx > n || ny < 1 || ny > m || s[nx][ny] == '#')
nx = x, ny = y;
return check(nx, ny, d, (k + 1) % (signed)now.size());
}
else if(now[k] >= 4 && now[k] <= 7)
return check(x, y, d, now[k] - 4);
else if(now[k] >= 8 && now[k] <= 11)
{
int nx = x + dx[d], ny = y + dy[d], nk = now[k] - 8;
if (nx < 1 || nx > n || ny < 1 || ny > m || s[nx][ny] == '#')
nk = (k + 1) % (signed)now.size();
return check(x, y, d, nk);
}
return 0;
}
void dfs(int dep)
{
if(dep > 1)
{
memset(f, 0, sizeof(f));
for (int i = 1; i <= m;++i)
if(s[1][i] == 'S' && check(1, i, 0, 0) && now.size() < ans.size())
ans = now;
}
if(dep == 5)
return;
for (int i = 1; i <= 11;++i)
{
if(i >= 4 && i <= 7 && (i - 3 == dep))
continue;
if(i >= 8 && i <= 11 && (i - 7 == dep))
continue;
now.push_back(i);
dfs(dep + 1);
now.pop_back();
}
return;
}
int main(void)
{
scanf("%d%d", &n, &m);
memset(s, '#', sizeof(s));
for (int i = 1; i <= n;++i)
scanf("%s", s[i] + 1), s[i][m + 1] = '#';
ans = {1, 12, 2, 5, 3};
dfs(1);
printf("%d\n", (signed)ans.size());
for(int x : ans)
{
if(x == 1)
puts("LEFT");
else if(x == 2)
puts("RIGHT");
else if(x == 3)
puts("FORWARD");
else if(x >= 4 && x <= 7)
printf("GOTO %d\n", x - 3);
else
printf("IF-OPEN %d\n", x - 7);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 3076kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 3ms
memory: 3072kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 1ms
memory: 3184kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 3ms
memory: 3068kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 4ms
memory: 3180kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 1ms
memory: 3228kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 1ms
memory: 3136kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 4ms
memory: 3232kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 3ms
memory: 3184kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 4ms
memory: 3272kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 1ms
memory: 3140kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 3ms
memory: 3072kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 1ms
memory: 3172kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 2ms
memory: 3232kb
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: 3068kb
input:
7 6 ...##S #..... ....#. ...#.# ....#. #..... .....G
output:
4 FORWARD RIGHT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #19:
score: 0
Accepted
time: 0ms
memory: 3220kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 3ms
memory: 3196kb
input:
3 10 ##.......S ####.####. ...#..G##.
output:
4 RIGHT FORWARD LEFT IF-OPEN 2
result:
ok correct answer!
Test #21:
score: 0
Accepted
time: 3ms
memory: 3252kb
input:
2 7 .#S.### .#.G..#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 1ms
memory: 3080kb
input:
2 7 .S#.#.# G#.##.#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 1ms
memory: 3072kb
input:
2 4 ...S ##G#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 1ms
memory: 3140kb
input:
2 7 S...... .G.....
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 1ms
memory: 3212kb
input:
2 3 #S# ..G
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 3ms
memory: 3180kb
input:
2 4 #.S# #G##
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 1ms
memory: 3064kb
input:
3 6 .#S### #....# #G.#..
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 1ms
memory: 3092kb
input:
2 4 S.#. #G##
output:
2 RIGHT FORWARD
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 3ms
memory: 3276kb
input:
2 5 ##..S ...G.
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 3ms
memory: 3068kb
input:
2 9 #S###.... G..##..##
output:
2 RIGHT FORWARD
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 1ms
memory: 3220kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
3 3 S.. ##. ##G
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 3ms
memory: 3176kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 3ms
memory: 3176kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 3ms
memory: 3248kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 3ms
memory: 3092kb
input:
4 3 ..S .#. ..# G..
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 3ms
memory: 3180kb
input:
5 3 S.. ##. ... ... .G.
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 1ms
memory: 3200kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 1ms
memory: 3172kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 1ms
memory: 3072kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 3ms
memory: 3216kb
input:
2 9 .##..S... ##..##G.#
output:
4 LEFT LEFT FORWARD LEFT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 3ms
memory: 3072kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 3ms
memory: 3196kb
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: 3196kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 3ms
memory: 3064kb
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: 3136kb
input:
2 7 #...S.. ..#G##.
output:
4 LEFT LEFT FORWARD RIGHT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 3ms
memory: 3068kb
input:
5 6 ...S.. ...#.. ...#.. ...#.# #G..#.
output:
4 RIGHT FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #49:
score: 0
Accepted
time: 2ms
memory: 3280kb
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: 3184kb
input:
3 4 #S.. ##.. .#G#
output:
4 LEFT FORWARD RIGHT IF-OPEN 2
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 0ms
memory: 3080kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 1ms
memory: 3088kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 3ms
memory: 3216kb
input:
5 5 #.#S# #...# ##.## ##..# .##.G
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #54:
score: 0
Accepted
time: 4ms
memory: 3180kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 3ms
memory: 3084kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 4ms
memory: 3252kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 4ms
memory: 3068kb
input:
4 5 S###. .#### .#### ..G##
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 3ms
memory: 3088kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 3ms
memory: 3172kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 0ms
memory: 3180kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 5ms
memory: 3136kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 4ms
memory: 3196kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 3ms
memory: 3252kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 1ms
memory: 3228kb
input:
10 10 ....#S.#.# .#....#... .....#..#. ....#..#.. .#.....#.# .......### #....#.#.. .......... .#.#.##... #....G.#..
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #65:
score: 0
Accepted
time: 3ms
memory: 3096kb
input:
10 10 #...#..#.S .##..#.... ..###.#... ##.##.##.. #.#..##..# .##.##...# ..#.##..#. ...#...##. .#.#....## #.##..G##.
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #66:
score: 0
Accepted
time: 4ms
memory: 3184kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 1ms
memory: 3180kb
input:
10 10 .....#...S ...#....#. ......#.## ..#......# #.#.##.#.. ..#.##.#.. .......#.. #...#..... #.#....#.. .#...#..#G
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #68:
score: 0
Accepted
time: 1ms
memory: 3184kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 3ms
memory: 3196kb
input:
10 10 ......##S. ........#. ....###... ....#.#..# .##....#.# .....#.... .....#.... ..##...... ....#.#.#. .#....G...
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #70:
score: 0
Accepted
time: 0ms
memory: 3220kb
input:
10 10 #.S#..#... .......#.# #..##..#.# #...#...#. #.###..##. .....#.#.# #.#..#...# ..##.#.#.# ####..#... ##..G#.#.#
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #71:
score: 0
Accepted
time: 1ms
memory: 3196kb
input:
10 10 S#...#.... .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. ...#...##G
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!
Test #72:
score: 0
Accepted
time: 3ms
memory: 3276kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 3ms
memory: 3068kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 4ms
memory: 3180kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 4ms
memory: 3216kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 3ms
memory: 3140kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!