QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#17917#2265. Short Coding2022zll#AC ✓2ms2012kbC++111.5kb2022-01-15 11:18:372022-05-04 16:18:44

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 16:18:44]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:2012kb
  • [2022-01-15 11:18:37]
  • 提交

answer

#include<cstdio>
#include<cstdlib>
#include<cstring>
const int maxn=12,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int n,m,sx,sy,tx,ty;
char s[maxn][maxn],op[6][8]={"","GOTO","IF-OPEN","FORWARD","LEFT","RIGHT"};
int a[6],b[6];
bool vis[maxn][maxn][4][5];
bool check(int lim){
	memset(vis,0,sizeof(vis));
	int d=0,x=sx,y=sy;
	while(true){
		for(int i=1;i<=lim;){
			if(vis[x][y][d][i])return false;
			if(x==tx&&y==ty)return true;
			vis[x][y][d][i]=true;
			int x_=x+dx[d],y_=y+dy[d];
			if(a[i]==1){
				i=b[i];
				continue;
			}else if(a[i]==2){
				if(x_>=1&&x_<=n&&y_>=1&&y_<=m&&s[x_][y_]!='#'){
					i=b[i];
					continue;
				}
			}else if(a[i]==3){
				if(x_>=1&&x_<=n&&y_>=1&&y_<=m&&s[x_][y_]!='#'){
					x=x_;
					y=y_;
				}
			}else if(a[i]==4){
				d=(d+1)&3;
			}else{
				d=(d+3)&3;
			}
			i++;
		}
	}
}
void dfs(int x,int lim){
	if(x==lim+1){
		if(check(lim)){
			printf("%d\n",lim);
			for(int i=1;i<=lim;i++){
				if(a[i]<=2)printf("%s %d\n",op[a[i]],b[i]);
				else puts(op[a[i]]);
			}
			exit(0);
		}
		return;
	}
	for(int i=1;i<=2;i++)
		for(int j=1;j<=lim;j++){
			a[x]=i,b[x]=j;
			dfs(x+1,lim);
		}
	for(int i=3;i<=5;i++){
		a[x]=i;
		dfs(x+1,lim);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='S')sx=i,sy=j;
			else if(s[i][j]=='G')tx=i,ty=j;
	for(int i=1;i<=4;i++)dfs(1,i);
	puts("5");
	puts("LEFT");
	puts("IF-OPEN 5");
	puts("RIGHT");
	puts("GOTO 2");
	puts("FORWARD");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 2008kb

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

3 6
##S..#
#..##.
.G..#.

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

score: 0
Accepted
time: 0ms
memory: 1828kb

input:

3 7
....S##
.#.#...
##.#.G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

score: 0
Accepted
time: 2ms
memory: 1768kb

input:

4 8
...S.#.#
##..#.#.
###...#.
#.#.#G.#

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

score: 0
Accepted
time: 0ms
memory: 1768kb

input:

3 5
.S#..
.....
..#G.

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

10 10
.....S#...
...#......
....##....
.#.....#..
....#.....
..#.......
...#......
..........
.#...#....
G.#..#...#

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

score: 0
Accepted
time: 1ms
memory: 1820kb

input:

7 9
.##S.#..#
.........
.........
...#...##
###..####
........#
.....##G#

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

score: 0
Accepted
time: 0ms
memory: 1768kb

input:

3 9
..#.#.#S#
#...#...#
.G....#.#

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

4 5
#S...
..#..
.#..#
.#.G#

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

score: 0
Accepted
time: 2ms
memory: 1812kb

input:

6 8
..S..#.#
...#...#
....#..#
#.#.##..
.......#
.#..#G.#

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

score: 0
Accepted
time: 2ms
memory: 1712kb

input:

9 10
S.........
.#..#....#
........#.
..........
.....#.#..
.#...#....
#..#.##.#.
..#..#...#
..#.#....G

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

score: 0
Accepted
time: 1ms
memory: 1964kb

input:

10 4
#.S.
.#.#
##.#
##..
.#..
#...
#.##
..#.
.#..
G.##

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

score: 0
Accepted
time: 2ms
memory: 1760kb

input:

9 9
#..#...S#
.#...##.#
.....##..
..#..#...
..#..#..#
.#..#.#.#
.###.....
..#.#.##.
G#....#.#

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #14:

score: 0
Accepted
time: 2ms
memory: 1880kb

input:

7 3
.S#
#..
..#
...
..#
.#.
.G.

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #15:

score: 0
Accepted
time: 0ms
memory: 1820kb

input:

6 6
..#S..
#.#.#.
.....#
#.#...
..#...
..G##.

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

score: 0
Accepted
time: 2ms
memory: 1772kb

input:

6 8
....#S..
......#.
..##..#.
###.#.##
..#...#.
##.G#..#

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

score: 0
Accepted
time: 2ms
memory: 1824kb

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: 1772kb

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: 1772kb

input:

4 8
.##..S..
#.###..#
.#...#..
...#G...

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

score: 0
Accepted
time: 2ms
memory: 1776kb

input:

3 10
##.......S
####.####.
...#..G##.

output:

4
RIGHT
FORWARD
LEFT
IF-OPEN 2

result:

ok correct answer!

Test #21:

score: 0
Accepted
time: 1ms
memory: 1880kb

input:

2 7
.#S.###
.#.G..#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #22:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

2 7
.S#.#.#
G#.##.#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #23:

score: 0
Accepted
time: 0ms
memory: 1824kb

input:

2 4
...S
##G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #24:

score: 0
Accepted
time: 1ms
memory: 1776kb

input:

2 7
S......
.G.....

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #25:

score: 0
Accepted
time: 1ms
memory: 1776kb

input:

2 3
#S#
..G

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #26:

score: 0
Accepted
time: 1ms
memory: 1780kb

input:

2 4
#.S#
#G##

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #27:

score: 0
Accepted
time: 0ms
memory: 2012kb

input:

3 6
.#S###
#....#
#G.#..

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #28:

score: 0
Accepted
time: 1ms
memory: 1812kb

input:

2 4
S.#.
#G##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #29:

score: 0
Accepted
time: 1ms
memory: 1824kb

input:

2 5
##..S
...G.

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #30:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

2 9
#S###....
G..##..##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #31:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

6 10
....S...##
.#...#....
..........
.#.#...#..
...#.##...
.G#...#...

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

score: 0
Accepted
time: 1ms
memory: 1820kb

input:

3 3
S..
##.
##G

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #33:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

5 5
..S..
.##..
.####
..#..
G.#.#

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #34:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

4 6
S#....
....#.
#.....
#...G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #35:

score: 0
Accepted
time: 1ms
memory: 1812kb

input:

3 6
.#..S#
..#..#
.##G.#

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #36:

score: 0
Accepted
time: 1ms
memory: 1876kb

input:

4 3
..S
.#.
..#
G..

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #37:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

5 3
S..
##.
...
...
.G.

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #38:

score: 0
Accepted
time: 1ms
memory: 1824kb

input:

8 2
.S
..
..
..
..
..
.#
G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #39:

score: 0
Accepted
time: 0ms
memory: 1776kb

input:

3 7
...#..S
#.#....
....G..

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #40:

score: 0
Accepted
time: 1ms
memory: 1828kb

input:

3 9
#......S.
...#.#...
.G.#.#...

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #41:

score: 0
Accepted
time: 2ms
memory: 1964kb

input:

2 9
.##..S...
##..##G.#

output:

4
IF-OPEN 3
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #42:

score: 0
Accepted
time: 2ms
memory: 1824kb

input:

4 6
S..#.#
..#...
......
..#G#.

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #43:

score: 0
Accepted
time: 2ms
memory: 1772kb

input:

4 9
#..##S..#
##..#...#
#.......#
####.#G##

output:

4
IF-OPEN 3
LEFT
LEFT
FORWARD

result:

ok correct answer!

Test #44:

score: 0
Accepted
time: 2ms
memory: 1768kb

input:

3 8
....S...
.....#..
..#G#...

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #45:

score: 0
Accepted
time: 2ms
memory: 1768kb

input:

4 9
.#.S#####
..#.###..
.#....#.#
.####.G.#

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #46:

score: 0
Accepted
time: 2ms
memory: 1812kb

input:

4 3
..S
...
...
#G#

output:

4
IF-OPEN 3
LEFT
LEFT
FORWARD

result:

ok correct answer!

Test #47:

score: 0
Accepted
time: 2ms
memory: 1768kb

input:

2 7
#...S..
..#G##.

output:

4
IF-OPEN 3
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #48:

score: 0
Accepted
time: 0ms
memory: 1772kb

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: 1964kb

input:

4 8
.#...#.S
..###...
........
....G..#

output:

4
FORWARD
IF-OPEN 4
LEFT
LEFT

result:

ok correct answer!

Test #50:

score: 0
Accepted
time: 2ms
memory: 1820kb

input:

3 4
#S..
##..
.#G#

output:

4
IF-OPEN 3
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #51:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

4 6
#.S.#.
#..#..
..#...
..G##.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #52:

score: 0
Accepted
time: 2ms
memory: 2012kb

input:

4 5
#..S.
#.#..
..#..
G#..#

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #53:

score: 0
Accepted
time: 2ms
memory: 1804kb

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: 1ms
memory: 1736kb

input:

5 6
##S..#
...#..
...#.#
...#..
..#G.#

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #55:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

6 4
...S
..#.
....
....
....
G...

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #56:

score: 0
Accepted
time: 1ms
memory: 1768kb

input:

5 6
....S.
......
......
....#.
....G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #57:

score: 0
Accepted
time: 1ms
memory: 1768kb

input:

4 5
S###.
.####
.####
..G##

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #58:

score: 0
Accepted
time: 1ms
memory: 1824kb

input:

6 5
...S.
...#.
.#...
..##.
.##..
.G#..

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #59:

score: 0
Accepted
time: 1ms
memory: 1816kb

input:

5 4
..S.
#...
.#..
..#.
G...

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #60:

score: 0
Accepted
time: 1ms
memory: 1772kb

input:

5 5
..#S#
.#..#
....#
..#.#
###G.

output:

1
FORWARD

result:

ok correct answer!

Test #61:

score: 0
Accepted
time: 2ms
memory: 1776kb

input:

10 10
#...S..#..
..#...#...
..#.#.#...
...#....##
##.....#.#
.....#.##.
.....#...#
...###....
..#.#.....
.#.#....#G

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #62:

score: 0
Accepted
time: 1ms
memory: 1824kb

input:

10 10
.#..S#...#
.....#....
...#...#.#
.##..#....
#....###.#
........##
...#..#...
##.#....##
...#....#.
#.#G...#.#

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #63:

score: 0
Accepted
time: 1ms
memory: 1884kb

input:

10 10
.......S..
..........
..........
..........
........#.
..........
..........
..........
..........
........G.

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #64:

score: 0
Accepted
time: 0ms
memory: 1824kb

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: 1772kb

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: 1ms
memory: 1768kb

input:

10 10
.........S
..........
..#.......
..........
.....#....
.#........
..........
..........
.......#..
.G.......#

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #67:

score: 0
Accepted
time: 2ms
memory: 1768kb

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: 1820kb

input:

10 10
......S...
..........
..........
..........
..........
...#....#.
..........
#.....#...
..........
.....#G...

output:

3
IF-OPEN 3
RIGHT
FORWARD

result:

ok correct answer!

Test #69:

score: 0
Accepted
time: 0ms
memory: 1824kb

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: 1820kb

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: 2ms
memory: 1824kb

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: 1ms
memory: 1768kb

input:

10 10
S#..#...#.
.#.....#..
.#.....#..
.........#
##.#.#.#..
.#.#.#.#..
.#.#.#.#.#
.#.#.#.#..
.#.#.#.#..
...#...#.G

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #73:

score: 0
Accepted
time: 2ms
memory: 1768kb

input:

10 10
S.#.#.#.#.
#..#.#.#.#
.#..#.#.#.
#.#..#.#.#
.#.#..#.#.
#.#.#..#.#
.#.#.#..#.
#.#.#.#..#
.#.#.#.#..
#.#.#.#.#G

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #74:

score: 0
Accepted
time: 1ms
memory: 1768kb

input:

10 10
S.........
.########.
.#......#.
.#......#.
.#......#.
.#......#.
.#......#.
.#......#.
.########.
.........G

output:

3
IF-OPEN 3
LEFT
FORWARD

result:

ok correct answer!

Test #75:

score: 0
Accepted
time: 2ms
memory: 1772kb

input:

10 10
S.#.......
#.###.####
#......#.#
##.###....
.#.#...#.#
...#####.#
.#.#.#...#
.#.#...###
##.#####.#
.........G

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #76:

score: 0
Accepted
time: 2ms
memory: 1772kb

input:

10 10
S.#.......
#.###.####
#......#.#
##.###....
.#.#...#.#
...#####.#
.#.#.#...#
.#.#...###
##.#####.#
G.........

output:

5
LEFT
IF-OPEN 5
RIGHT
GOTO 2
FORWARD

result:

ok correct answer!