QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#18164#2265. Short CodingAppleblue17#WA 38ms3780kbC++1.9kb2022-01-16 16:44:022022-05-04 17:14:35

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 17:14:35]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:3780kb
  • [2022-01-16 16:44:02]
  • 提交

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];
			nw=p;
		}
		else if(pat[nw]<=10){
			int p=pat[nw]-5;
			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;
		}
	}
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 3716kb

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

score: 0
Accepted
time: 4ms
memory: 3516kb

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

score: 0
Accepted
time: 7ms
memory: 3632kb

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

score: 0
Accepted
time: 7ms
memory: 3632kb

input:

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

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

score: 0
Accepted
time: 6ms
memory: 3632kb

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

score: 0
Accepted
time: 3ms
memory: 3712kb

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

score: 0
Accepted
time: 3ms
memory: 3636kb

input:

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

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

score: 0
Accepted
time: 3ms
memory: 3740kb

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

score: 0
Accepted
time: 25ms
memory: 3780kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

score: 0
Accepted
time: 23ms
memory: 3632kb

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

score: 0
Accepted
time: 26ms
memory: 3716kb

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

score: 0
Accepted
time: 38ms
memory: 3516kb

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #14:

score: 0
Accepted
time: 23ms
memory: 3712kb

input:

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

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #15:

score: 0
Accepted
time: 26ms
memory: 3712kb

input:

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

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

score: 0
Accepted
time: 19ms
memory: 3780kb

input:

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

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

score: 0
Accepted
time: 26ms
memory: 3732kb

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

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

input:

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

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

score: 0
Accepted
time: 17ms
memory: 3512kb

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #22:

score: 0
Accepted
time: 4ms
memory: 3720kb

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #23:

score: 0
Accepted
time: 4ms
memory: 3632kb

input:

2 4
...S
##G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #24:

score: 0
Accepted
time: 4ms
memory: 3712kb

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #25:

score: 0
Accepted
time: 4ms
memory: 3740kb

input:

2 3
#S#
..G

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #26:

score: 0
Accepted
time: 4ms
memory: 3512kb

input:

2 4
#.S#
#G##

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #27:

score: 0
Accepted
time: 4ms
memory: 3732kb

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #28:

score: 0
Accepted
time: 4ms
memory: 3656kb

input:

2 4
S.#.
#G##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #29:

score: 0
Accepted
time: 4ms
memory: 3520kb

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #30:

score: 0
Accepted
time: 4ms
memory: 3664kb

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #31:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

score: 0
Accepted
time: 5ms
memory: 3620kb

input:

3 3
S..
##.
##G

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #33:

score: -100
Wrong Answer
time: 5ms
memory: 3652kb

input:

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

output:

3
FORWARD
IF-OPEN 5
LEFT

result:

wrong answer Integer 5 violates the range [1, 3]