QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#18035 | #2265. Short Coding | _silhouette_# | AC ✓ | 25ms | 3892kb | C++ | 2.2kb | 2022-01-15 20:01:54 | 2022-05-04 16:43:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,Ans[10],A[10],vis[15][15][10][5];
char a[15][15];
void Print(int x){
if(x==1) puts("LEFT");
if(x==2) puts("RIGHT");
if(x==3) puts("FORWARD");
if(x==4) puts("IF-OPEN 1");
if(x==5) puts("IF-OPEN 2");
if(x==6) puts("IF-OPEN 3");
if(x==7) puts("IF-OPEN 4");
if(x==8) puts("GOTO 1");
if(x==9) puts("GOTO 2");
if(x==10) puts("GOTO 3");
if(x==11) puts("GOTO 4");
}
bool dfs(int x,int y,int op,int f,int tot){//DLUR
if(op>tot) return dfs(x,y,op-tot,f,tot);
if(vis[x][y][op][f]) return false;
if(a[x][y]=='G') return true;
vis[x][y][op][f]=1;
if(A[op]==1) return dfs(x,y,op+1,(f+3)%4,tot);
if(A[op]==2) return dfs(x,y,op+1,(f+1)%4,tot);
if(A[op]==3){
if(f==0)
if(x+1<=n&&a[x+1][y]!='#') return dfs(x+1,y,op+1,f,tot);
if(f==1)
if(y-1>=1&&a[x][y-1]!='#') return dfs(x,y-1,op+1,f,tot);
if(f==2)
if(x-1>=1&&a[x-1][y]!='#') return dfs(x-1,y,op+1,f,tot);
if(f==3)
if(y+1<=m&&a[x][y+1]!='#') return dfs(x,y+1,op+1,f,tot);
return dfs(x,y,op+1,f,tot);
}
if(A[op]>=4&&A[op]<=7){
if(f==0)
if(x+1<=n&&a[x+1][y]!='#') return dfs(x,y,A[op]-3,f,tot);
if(f==1)
if(y-1>=1&&a[x][y-1]!='#') return dfs(x,y,A[op]-3,f,tot);
if(f==2)
if(x-1>=1&&a[x-1][y]!='#') return dfs(x,y,A[op]-3,f,tot);
if(f==3)
if(y+1<=m&&a[x][y+1]!='#') return dfs(x,y,A[op]-3,f,tot);
return dfs(x,y,op+1,f,tot);
}
return dfs(x,y,A[op]-7,f,tot);
}
bool chck(int tot){
if(tot==0) return false;
for(int i=1;i<=tot;i++)
if((4<=A[i]&&A[i]<=7&&A[i]-3>tot)||(A[i]>7&&A[i]-7>tot)) return false;
int sx=1,sy=0;
for(int i=1;i<=m;i++)
if(a[1][i]=='S') sy=i;
memset(vis,0,sizeof(vis));
return dfs(sx,sy,1,0,tot);
}
void dfs(int x){
if(x-1>=ans) return;
if(chck(x-1)){
ans=x-1;
for(int i=1;i<=ans;i++) Ans[i]=A[i];
}
for(int i=1;i<=11;i++) A[x]=i,dfs(x+1);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
ans=5; dfs(1);
if(ans==5){
puts("5");
puts("RIGHT");
puts("IF-OPEN 5");
puts("LEFT");
puts("GOTO 2");
puts("FORWARD");
} else {
printf("%d\n",ans);
for(int i=1;i<=ans;i++) Print(Ans[i]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3800kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 4ms
memory: 3848kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 3ms
memory: 3892kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 7ms
memory: 3836kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 2ms
memory: 3800kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 5ms
memory: 3820kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 5ms
memory: 3824kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 5ms
memory: 3828kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 4ms
memory: 3804kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 8ms
memory: 3828kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 6ms
memory: 3840kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 7ms
memory: 3752kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 7ms
memory: 3752kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 8ms
memory: 3840kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 5ms
memory: 3820kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 8ms
memory: 3820kb
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: 3688kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 6ms
memory: 3888kb
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: 3808kb
input:
2 7 .#S.### .#.G..#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
2 7 .S#.#.# G#.##.#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
2 4 ...S ##G#
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 2ms
memory: 3828kb
input:
2 7 S...... .G.....
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
2 3 #S# ..G
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 3ms
memory: 3820kb
input:
2 4 #.S# #G##
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
3 6 .#S### #....# #G.#..
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 4ms
memory: 3728kb
input:
2 4 S.#. #G##
output:
2 RIGHT FORWARD
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 3ms
memory: 3772kb
input:
2 5 ##..S ...G.
output:
2 LEFT FORWARD
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
2 9 #S###.... G..##..##
output:
2 RIGHT FORWARD
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 3ms
memory: 3848kb
input:
3 3 S.. ##. ##G
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 3ms
memory: 3892kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 5ms
memory: 3756kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 3ms
memory: 3832kb
input:
4 3 ..S .#. ..# G..
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 5ms
memory: 3772kb
input:
5 3 S.. ##. ... ... .G.
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 LEFT FORWARD FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 3ms
memory: 3808kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 4ms
memory: 3800kb
input:
2 9 .##..S... ##..##G.#
output:
4 LEFT LEFT FORWARD LEFT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 4ms
memory: 3832kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 4ms
memory: 3828kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 LEFT LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 4ms
memory: 3832kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 4ms
memory: 3688kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
4 3 ..S ... ... #G#
output:
4 LEFT LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #47:
score: 0
Accepted
time: 4ms
memory: 3728kb
input:
2 7 #...S.. ..#G##.
output:
4 LEFT LEFT FORWARD RIGHT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 6ms
memory: 3800kb
input:
5 6 ...S.. ...#.. ...#.. ...#.# #G..#.
output:
4 RIGHT FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #49:
score: 0
Accepted
time: 4ms
memory: 3828kb
input:
4 8 .#...#.S ..###... ........ ....G..#
output:
4 LEFT LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #50:
score: 0
Accepted
time: 4ms
memory: 3892kb
input:
3 4 #S.. ##.. .#G#
output:
4 LEFT FORWARD RIGHT IF-OPEN 2
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 3ms
memory: 3728kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 3ms
memory: 3848kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 18ms
memory: 3764kb
input:
5 5 #.#S# #...# ##.## ##..# .##.G
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #54:
score: 0
Accepted
time: 3ms
memory: 3820kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 2ms
memory: 3792kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 3ms
memory: 3776kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 3ms
memory: 3728kb
input:
4 5 S###. .#### .#### ..G##
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 3ms
memory: 3800kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 2ms
memory: 3820kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 3ms
memory: 3732kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 4ms
memory: 3804kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 2ms
memory: 3824kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 3ms
memory: 3888kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 23ms
memory: 3828kb
input:
10 10 ....#S.#.# .#....#... .....#..#. ....#..#.. .#.....#.# .......### #....#.#.. .......... .#.#.##... #....G.#..
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #65:
score: 0
Accepted
time: 21ms
memory: 3708kb
input:
10 10 #...#..#.S .##..#.... ..###.#... ##.##.##.. #.#..##..# .##.##...# ..#.##..#. ...#...##. .#.#....## #.##..G##.
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #66:
score: 0
Accepted
time: 3ms
memory: 3688kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 25ms
memory: 3708kb
input:
10 10 .....#...S ...#....#. ......#.## ..#......# #.#.##.#.. ..#.##.#.. .......#.. #...#..... #.#....#.. .#...#..#G
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #68:
score: 0
Accepted
time: 5ms
memory: 3684kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 23ms
memory: 3828kb
input:
10 10 ......##S. ........#. ....###... ....#.#..# .##....#.# .....#.... .....#.... ..##...... ....#.#.#. .#....G...
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #70:
score: 0
Accepted
time: 17ms
memory: 3708kb
input:
10 10 #.S#..#... .......#.# #..##..#.# #...#...#. #.###..##. .....#.#.# #.#..#...# ..##.#.#.# ####..#... ##..G#.#.#
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #71:
score: 0
Accepted
time: 24ms
memory: 3824kb
input:
10 10 S#...#.... .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. ...#...##G
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!
Test #72:
score: 0
Accepted
time: 5ms
memory: 3820kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 2ms
memory: 3888kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 4ms
memory: 3804kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 25ms
memory: 3760kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 RIGHT IF-OPEN 5 LEFT GOTO 2 FORWARD
result:
ok correct answer!