QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515395 | #2265. Short Coding | IllusionaryDominance# | AC ✓ | 5ms | 3712kb | C++14 | 5.1kb | 2024-08-11 17:33:25 | 2024-08-11 17:33:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
const int fx[4] = {1, 0, -1, 0};
const int fy[4] = {0, -1, 0, 1};
struct Code{
int op, gt;
}ans[N], now[N];
int flag, len = 1;
int us1[N], us3[N];
int n, m;
char s[N][N];
int vis[10000000];
int calc(int x, int y, int dir, int ln){return ((x - 1) * m + y) * 4 * len + (ln - 1) * 4 + dir;}
bool check(){
int x = 1, y, dir = 0, ln = 1;
for (y = 1; y <= m; ++ y) if(s[x][y] == 'S') break;
while(1){
// cout << x << " " << y << " " << dir << " " << ln << "\n";
if(s[x][y] == 'G') return 1;
if(vis[calc(x, y, dir, ln)]) break;
vis[calc(x, y, dir, ln)] = 1;
int dx = x + fx[dir], dy = y + fy[dir];
switch (now[ln].op)
{
case 1:
ln = now[ln].gt;
break;
case 2:
if(s[dx][dy] == '.' || s[dx][dy] == 'G' || s[dx][dy] == 'S') ln = now[ln].gt;
else ln = ln % len + 1;
break;
case 3:
if(s[dx][dy] == '.' || s[dx][dy] == 'G' || s[dx][dy] == 'S') x = dx, y = dy;
ln = ln % len + 1;
break;
case 4:
dir = (dir + 3) % 4;
ln = ln % len + 1;
break;
case 5:
dir = (dir + 1) % 4;
ln = ln % len + 1;
break;
}
}
x = 1, y, dir = 0, ln = 1;
for (y = 1; y <= m; ++ y) if(s[x][y] == 'S') break;
while(1){
if(s[x][y] == 'G') return 1;
if(vis[calc(x, y, dir, ln)] == 0) break;
vis[calc(x, y, dir, ln)] = 0;
int dx = x + fx[dir], dy = y + fy[dir];
switch (now[ln].op)
{
case 1:
ln = now[ln].gt;
break;
case 2:
if(s[dx][dy] == '.' || s[dx][dy] == 'G' || s[dx][dy] == 'S') ln = now[ln].gt;
else ln = ln % len + 1;
break;
case 3:
if(s[dx][dy] == '.' || s[dx][dy] == 'G' || s[dx][dy] == 'S') x = dx, y = dy;
ln = ln % len + 1;
break;
case 4:
dir = (dir + 3) % 4;
ln = ln % len + 1;
break;
case 5:
dir = (dir + 1) % 4;
ln = ln % len + 1;
break;
}
}
return 0;
}
void dfs(int o, int maxs){
if(o > maxs){
// for (int i = 1; i <= len; ++ i){
// switch (now[i].op)
// {
// case 1:
// cout << "GOTO " << now[i].gt << "\n";
// break;
// case 2:
// cout << "IF_OPEN " << now[i].gt << "\n";
// break;
// case 3:
// cout << "FORWARD\n";
// break;
// case 4:
// cout << "LEFT\n";
// break;
// case 5:
// cout << "RIGHT\n";
// break;
// }
// }
if(check()) flag = 1, memcpy(ans, now, sizeof(ans));
return;
}
for (int i = 1; i <= 5 && flag == 0; ++ i){
// if(now[o - 1].op == 1 && i == 1) continue;
// if(now[o - 1].op == 1 && i == 2) continue;
// if(now[o - 1].op == 2 && i == 2) continue;
// if(us1[o] && i == 1) continue;
// if(us3[o] && (i == 1 || i == 2)) continue;
now[o].op = i;
if(i == 1){
for (int j = 1; j <= maxs; ++ j){
if(o == j) continue;
if(j < i && now[i].op == 1) continue;
++ us1[j]; now[o].gt = j;
dfs(o + 1, maxs);
-- us1[j];
}
continue;
}
if(i == 2){
for (int j = 1; j <= maxs; ++ j){
if(o == j) continue;
if(j < i && (now[i].op == 1 || now[i].op == 2)) continue;
++ us3[j]; now[o].gt = j;
dfs(o + 1, maxs);
-- us3[j];
}
continue;
}
dfs(o + 1, maxs);
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++ i) cin >> s[i] + 1;
while(1){
dfs(1, len);
if(flag) break;
++ len;
}
cout << len << "\n";
for (int i = 1; i <= len; ++ i){
switch (ans[i].op)
{
case 1:
cout << "GOTO " << ans[i].gt << "\n";
break;
case 2:
cout << "IF-OPEN " << ans[i].gt << "\n";
break;
case 3:
cout << "FORWARD\n";
break;
case 4:
cout << "LEFT\n";
break;
case 5:
cout << "RIGHT\n";
break;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 0ms
memory: 3580kb
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: 3632kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 1ms
memory: 3708kb
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: 3552kb
input:
2 7 .#S.### .#.G..#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 7 .S#.#.# G#.##.#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 4 ...S ##G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
2 7 S...... .G.....
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 3 #S# ..G
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
2 4 #.S# #G##
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
3 6 .#S### #....# #G.#..
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 4 S.#. #G##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
2 5 ##..S ...G.
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
2 9 #S###.... G..##..##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 3 S.. ##. ##G
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4 3 ..S .#. ..# G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 3 S.. ##. ... ... .G.
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
2 9 .##..S... ##..##G.#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
4 3 ..S ... ... #G#
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #47:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
2 7 #...S.. ..#G##.
output:
4 IF-OPEN 3 RIGHT FORWARD LEFT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 1ms
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: 1ms
memory: 3648kb
input:
4 8 .#...#.S ..###... ........ ....G..#
output:
4 FORWARD IF-OPEN 4 LEFT LEFT
result:
ok correct answer!
Test #50:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
3 4 #S.. ##.. .#G#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 4ms
memory: 3628kb
input:
5 5 #.#S# #...# ##.## ##..# .##.G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #54:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 5 S###. .#### .#### ..G##
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 4ms
memory: 3588kb
input:
10 10 ....#S.#.# .#....#... .....#..#. ....#..#.. .#.....#.# .......### #....#.#.. .......... .#.#.##... #....G.#..
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #65:
score: 0
Accepted
time: 4ms
memory: 3592kb
input:
10 10 #...#..#.S .##..#.... ..###.#... ##.##.##.. #.#..##..# .##.##...# ..#.##..#. ...#...##. .#.#....## #.##..G##.
output:
5 GOTO 3 RIGHT FORWARD IF-OPEN 2 LEFT
result:
ok correct answer!
Test #66:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 4ms
memory: 3584kb
input:
10 10 .....#...S ...#....#. ......#.## ..#......# #.#.##.#.. ..#.##.#.. .......#.. #...#..... #.#....#.. .#...#..#G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #68:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 3ms
memory: 3588kb
input:
10 10 ......##S. ........#. ....###... ....#.#..# .##....#.# .....#.... .....#.... ..##...... ....#.#.#. .#....G...
output:
5 GOTO 3 LEFT FORWARD IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #70:
score: 0
Accepted
time: 4ms
memory: 3628kb
input:
10 10 #.S#..#... .......#.# #..##..#.# #...#...#. #.###..##. .....#.#.# #.#..#...# ..##.#.#.# ####..#... ##..G#.#.#
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #71:
score: 0
Accepted
time: 5ms
memory: 3628kb
input:
10 10 S#...#.... .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. ...#...##G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #72:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 3ms
memory: 3624kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!