QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515510 | #2265. Short Coding | Cheek_support | AC ✓ | 1ms | 3848kb | C++20 | 3.9kb | 2024-08-11 18:12:35 | 2024-08-11 18:12:36 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
#define DEBUG_ARR(arr, l, r) { \
cerr << "* "#arr"[" << l << ", " << r << "]:"; \
for(auto it = l, itr = r; it <= itr; it++) \
cerr << arr[it] << ", "; \
cerr << endl; \
}
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
#define DEBUG_HERE { DEBUG_FMT("Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__); }
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int N = 1024, M = 11;
const int LEN = 21;
int n, m;
char a[N][N];
struct Command
{
int type;
int l;
};
Command c[LEN];
bool vis[11][11][4][LEN];
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; // -> right
int sx, sy;
void print(int len)
{
cout << len << endl;
for(int i = 1; i <= len; i++) {
if(c[i].type == 1) {
cout << "GOTO " << c[i].l << endl;
} else if(c[i].type == 2) {
cout << "IF-OPEN " << c[i].l << endl;
} else if(c[i].type == 3) {
cout << "FORWARD" << endl;
} else if(c[i].type == 4) {
cout << "LEFT" << endl;
} else {
cout << "RIGHT" << endl;
}
}
}
void check(int len)
{
memset(vis, 0, sizeof vis);
int pc = 1;
int x = sx, y = sy;
int d = 2;
while(true) {
if(vis[x][y][d][pc]) return;
vis[x][y][d][pc] = true;
if(a[x][y] == 'G') break;
Command com = c[pc];
if(com.type == 1) { // GOTO
pc = com.l;
} else if(com.type == 2) { // IF-OPEN
int nx = x + dx[d], ny = y + dy[d];
bool is_open = true;
if(nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] == '#') {
is_open = false;
}
if(is_open) {
pc = com.l;
} else {
if(pc == len) pc = 1;
else pc++;
}
} else if(com.type == 3) { // FORWARD
int nx = x + dx[d], ny = y + dy[d];
bool is_open = true;
if(nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] == '#') {
is_open = false;
}
if(is_open) {
x = nx, y = ny;
}
if(pc == len) pc = 1;
else pc++;
} else if(com.type == 4) { // LEFT
d = (d + 4 - 1)%4;
if(pc == len) pc = 1;
else pc++;
} else {
d = (d + 1)%4;
if(pc == len) pc = 1;
else pc++;
}
}
print(len);
exit(0);
}
void dfs(int step, int max_step)
{
if(step > max_step) {
check(max_step);
return;
}
for(int i = 1; i <= 5; i++) {
c[step].type = i;
if(i == 1 || i == 2) {
for(int j = 1; j <= max_step; j++) {
if(j == step) continue;
c[step].l = j;
dfs(step + 1, max_step);
}
} else {
dfs(step + 1, max_step);
}
}
}
int main()
{
// freopen("1.in", "r", stdin);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%s", a[i] + 1);
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == 'S') {
sx = i, sy = j;
}
}
}
// c[1].type = 4;
// c[2].type = 3;
// c[3].type = 2; c[3].l = 2;
// check(3);
for(int i = 1; i < 5; i++) {
dfs(1, i);
}
// assert(false);
c[1].type = 4;
c[2].type = 2; c[2].l = 5;
c[3].type = 5;
c[4].type = 1; c[4].l = 2;
c[5].type = 3;
print(5);
// check(5);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 1ms
memory: 3840kb
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: 3836kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 1ms
memory: 3624kb
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: 3644kb
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: 3624kb
input:
2 4 ...S ##G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 7 S...... .G.....
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
2 3 #S# ..G
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 4 #.S# #G##
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 6 .#S### #....# #G.#..
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
2 4 S.#. #G##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
2 5 ##..S ...G.
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 9 #S###.... G..##..##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
3 3 S.. ##. ##G
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 3 ..S .#. ..# G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
5 3 S.. ##. ... ... .G.
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
2 9 .##..S... ##..##G.#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 1ms
memory: 3832kb
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: 3684kb
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: 3772kb
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: 3628kb
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: 3756kb
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: 3696kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 1ms
memory: 3756kb
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: 0ms
memory: 3744kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 0ms
memory: 3836kb
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: 3624kb
input:
4 5 S###. .#### .#### ..G##
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 1ms
memory: 3824kb
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: 0ms
memory: 3752kb
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: 0ms
memory: 3648kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 0ms
memory: 3708kb
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: 0ms
memory: 3844kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 1ms
memory: 3652kb
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: 1ms
memory: 3772kb
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: 3652kb
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: 0ms
memory: 3656kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!