QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#18168 | #2265. Short Coding | Appleblue17# | AC ✓ | 28ms | 3784kb | C++ | 2.0kb | 2022-01-16 16:50:28 | 2022-05-04 17:14:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=11;
int n,m,stx,sty,ans=5;
char s[N][N];
int fx[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
/*
1 GOTO 1
2 GOTO 2
3 GOTO 3
4 GOTO 4
5 GOTO 5
6 IF-OPEN 1
7 IF-OPEN 2
8 IF-OPEN 3
9 IF-OPEN 4
10 IF-OPEN 5
11 LEFT
12 RIGHT
13 FORWARD
*/
int pat[N],anspat[N];
bool vis[N][N][4][6];
bool check(int len){
memset(vis,0,sizeof(vis));
int x=stx,y=sty,nw=1,dir=0;
while(1){
if(vis[x][y][dir][nw]) return 0;
vis[x][y][dir][nw]=1;
if(s[x][y]=='G') return 1;
if(pat[nw]<=5){
int p=pat[nw];
if(p>len) return 0;
nw=p;
}
else if(pat[nw]<=10){
int p=pat[nw]-5;
if(p>len) return 0;
int nx=x+fx[dir][0],ny=y+fx[dir][1];
if(s[nx][ny]!='#' && nx>=1 && nx<=n && ny>=1 && ny<=m) nw=p;
else nw++;
}
else if(pat[nw]==11){
dir=(dir+3)%4;
nw++;
}
else if(pat[nw]==12){
dir=(dir+1)%4;
nw++;
}
else if(pat[nw]==13){
int nx=x+fx[dir][0],ny=y+fx[dir][1];
if(s[nx][ny]!='#' && nx>=1 && nx<=n && ny>=1 && ny<=m) x=nx,y=ny;
nw++;
}
if(nw>len) nw=1;
}
return 0;
}
void dfs(int dep){
if(dep>ans) return;
for(int i=1;i<=13;i++){
pat[dep]=i;
if(check(dep)){
if(dep<=ans){
ans=dep;
for(int i=1;i<=ans;i++) anspat[i]=pat[i];
}
return ;
}
dfs(dep+1);
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("\n%s",s[i]+1);
for(int j=1;j<=m;j++) if(s[i][j]=='S') stx=i,sty=j;
}
dfs(1);
cout<<ans<<endl;
for(int i=1;i<=ans;i++){
int x=anspat[i];
switch(x){
case 1:puts("GOTO 1");break;
case 2:puts("GOTO 2");break;
case 3:puts("GOTO 3");break;
case 4:puts("GOTO 4");break;
case 5:puts("GOTO 5");break;
case 6:puts("IF-OPEN 1");break;
case 7:puts("IF-OPEN 2");break;
case 8:puts("IF-OPEN 3");break;
case 9:puts("IF-OPEN 4");break;
case 10:puts("IF-OPEN 5");break;
case 11:puts("LEFT");break;
case 12:puts("RIGHT");break;
case 13:puts("FORWARD");break;
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3732kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 4ms
memory: 3748kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 4ms
memory: 3628kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 3ms
memory: 3516kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 6ms
memory: 3784kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 2ms
memory: 3732kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 6ms
memory: 3744kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 7ms
memory: 3620kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 25ms
memory: 3628kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 23ms
memory: 3628kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 28ms
memory: 3652kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 24ms
memory: 3636kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 26ms
memory: 3724kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 22ms
memory: 3720kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 27ms
memory: 3712kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 27ms
memory: 3712kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 26ms
memory: 3712kb
input:
7 6 ...##S #..... ....#. ...#.# ....#. #..... .....G
output:
4 FORWARD RIGHT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #19:
score: 0
Accepted
time: 23ms
memory: 3720kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 20ms
memory: 3632kb
input:
3 10 ##.......S ####.####. ...#..G##.
output:
4 RIGHT FORWARD LEFT IF-OPEN 2
result:
ok correct answer!
Test #21:
score: 0
Accepted
time: 4ms
memory: 3732kb
input:
2 7 .#S.### .#.G..#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 5ms
memory: 3656kb
input:
2 7 .S#.#.# G#.##.#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 2ms
memory: 3632kb
input:
2 4 ...S ##G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 4ms
memory: 3728kb
input:
2 7 S...... .G.....
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 4ms
memory: 3784kb
input:
2 3 #S# ..G
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
2 4 #.S# #G##
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 4ms
memory: 3628kb
input:
3 6 .#S### #....# #G.#..
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 4ms
memory: 3516kb
input:
2 4 S.#. #G##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
2 5 ##..S ...G.
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 4ms
memory: 3620kb
input:
2 9 #S###.... G..##..##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 6ms
memory: 3668kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 8ms
memory: 3632kb
input:
3 3 S.. ##. ##G
output:
3 FORWARD FORWARD RIGHT
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 7ms
memory: 3652kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 5ms
memory: 3712kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 5ms
memory: 3624kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 FORWARD FORWARD RIGHT
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
4 3 ..S .#. ..# G..
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 5ms
memory: 3628kb
input:
5 3 S.. ##. ... ... .G.
output:
3 FORWARD FORWARD RIGHT
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 6ms
memory: 3712kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 5ms
memory: 3708kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 15ms
memory: 3716kb
input:
2 9 .##..S... ##..##G.#
output:
4 FORWARD FORWARD FORWARD RIGHT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 18ms
memory: 3780kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 15ms
memory: 3716kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 FORWARD IF-OPEN 4 LEFT LEFT
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 21ms
memory: 3624kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 21ms
memory: 3636kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 11ms
memory: 3632kb
input:
4 3 ..S ... ... #G#
output:
4 FORWARD IF-OPEN 4 RIGHT RIGHT
result:
ok correct answer!
Test #47:
score: 0
Accepted
time: 15ms
memory: 3720kb
input:
2 7 #...S.. ..#G##.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 23ms
memory: 3708kb
input:
5 6 ...S.. ...#.. ...#.. ...#.# #G..#.
output:
4 RIGHT FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #49:
score: 0
Accepted
time: 18ms
memory: 3516kb
input:
4 8 .#...#.S ..###... ........ ....G..#
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #50:
score: 0
Accepted
time: 17ms
memory: 3632kb
input:
3 4 #S.. ##.. .#G#
output:
4 LEFT FORWARD RIGHT IF-OPEN 2
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 5ms
memory: 3548kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 20ms
memory: 3668kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 25ms
memory: 3716kb
input:
5 5 #.#S# #...# ##.## ##..# .##.G
output:
5 FORWARD RIGHT IF-OPEN 1 RIGHT RIGHT
result:
ok correct answer!
Test #54:
score: 0
Accepted
time: 6ms
memory: 3632kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 5ms
memory: 3724kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 5ms
memory: 3584kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 5ms
memory: 3584kb
input:
4 5 S###. .#### .#### ..G##
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 5ms
memory: 3632kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 6ms
memory: 3732kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 4ms
memory: 3580kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 21ms
memory: 3732kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 6ms
memory: 3716kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 4ms
memory: 3512kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 26ms
memory: 3512kb
input:
10 10 ....#S.#.# .#....#... .....#..#. ....#..#.. .#.....#.# .......### #....#.#.. .......... .#.#.##... #....G.#..
output:
5 FORWARD RIGHT IF-OPEN 1 LEFT GOTO 3
result:
ok correct answer!
Test #65:
score: 0
Accepted
time: 26ms
memory: 3712kb
input:
10 10 #...#..#.S .##..#.... ..###.#... ##.##.##.. #.#..##..# .##.##...# ..#.##..#. ...#...##. .#.#....## #.##..G##.
output:
5 FORWARD LEFT IF-OPEN 1 RIGHT GOTO 3
result:
ok correct answer!
Test #66:
score: 0
Accepted
time: 3ms
memory: 3720kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 21ms
memory: 3740kb
input:
10 10 .....#...S ...#....#. ......#.## ..#......# #.#.##.#.. ..#.##.#.. .......#.. #...#..... #.#....#.. .#...#..#G
output:
5 FORWARD RIGHT IF-OPEN 1 LEFT GOTO 3
result:
ok correct answer!
Test #68:
score: 0
Accepted
time: 3ms
memory: 3580kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 22ms
memory: 3624kb
input:
10 10 ......##S. ........#. ....###... ....#.#..# .##....#.# .....#.... .....#.... ..##...... ....#.#.#. .#....G...
output:
5 FORWARD RIGHT IF-OPEN 1 LEFT GOTO 3
result:
ok correct answer!
Test #70:
score: 0
Accepted
time: 26ms
memory: 3712kb
input:
10 10 #.S#..#... .......#.# #..##..#.# #...#...#. #.###..##. .....#.#.# #.#..#...# ..##.#.#.# ####..#... ##..G#.#.#
output:
5 FORWARD LEFT IF-OPEN 1 RIGHT GOTO 3
result:
ok correct answer!
Test #71:
score: 0
Accepted
time: 26ms
memory: 3664kb
input:
10 10 S#...#.... .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. ...#...##G
output:
5 FORWARD RIGHT IF-OPEN 1 RIGHT RIGHT
result:
ok correct answer!
Test #72:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 22ms
memory: 3712kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 7ms
memory: 3624kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 FORWARD IF-OPEN 1 LEFT
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 22ms
memory: 3720kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 25ms
memory: 3632kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 FORWARD RIGHT IF-OPEN 1 RIGHT RIGHT
result:
ok correct answer!