QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18027#2265. Short CodingJohnAlfnov#AC ✓9ms3884kbC++142.0kb2022-01-15 19:11:182022-05-04 16:42:53

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:42:53]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:3884kb
  • [2022-01-15 19:11:18]
  • 提交

answer

#include<bits/stdc++.h>
#define l(x,y) apple(x,y)
using namespace std;
string zl[6]={"","LEFT","FORWARD","RIGHT","GOTO","IF-OPEN"};
struct apple{
	int lz,zz;
	apple(int lz=0,int zz=0):lz(lz),zz(zz){}
}st[19]={l(0,0),l(1,-1),l(2,-1),l(3,-1),l(4,1),l(4,2),
l(4,3),l(4,4),l(5,1),l(5,2),l(5,3),l(5,4),l(5,5)};
const int gs=11;
int n,m;
char s[13][13];
int ans=5;
int mp[6]={0,1,12,3,5,2},pm[6];
struct dij{
	int x,y,mc,zl;
	dij(int x=0,int y=0,int mc=0,int zl=0):
		x(x),y(y),mc(mc),zl(zl){}
	bool operator<(const dij &other)const{
		if(x!=other.x)return x<other.x;
		if(y!=other.y)return y<other.y;
		if(mc!=other.mc)return mc<other.mc;
		return zl<other.zl;
	}
};
int Spx=-1,Spy=-1,Grx=-1,Gry=-1;
int mb[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
bool ok(int x){
	if(x==0)return false;
	map<dij,int>mp;
	dij d(Spx,Spy,2,1);
	while(d.x!=Grx||d.y!=Gry){
		if(mp[d])return false;
		mp[d]=1;
		auto z=st[pm[d.zl]];
		if(z.lz==1){
			d.mc=(d.mc+3)&3;
			d.zl=d.zl%x+1;
		}else if(z.lz==2){
			int dx=d.x+mb[d.mc][0],dy=d.y+mb[d.mc][1];
			if(dx>=1&&dx<=n&&dy>=1&&dy<=m)
				if(s[dx][dy]!='#')d.x=dx,d.y=dy;
			d.zl=d.zl%x+1;
		}else if(z.lz==3){
			d.mc=(d.mc+1)&3;
			d.zl=d.zl%x+1;
		}else if(z.lz==4){
			d.zl=z.zz;
		}else if(z.lz==5){
			int dx=d.x+mb[d.mc][0],dy=d.y+mb[d.mc][1];
			int flag=0;
			if(dx>=1&&dx<=n&&dy>=1&&dy<=m)
				if(s[dx][dy]!='#')d.zl=z.zz,flag=1;
			if(!flag)d.zl=d.zl%x+1;
		}else assert(0);
	}
	return true;
}
void dfs(int stp){
	if(stp>ans)return;
	if(ok(stp-1)){
		ans=stp-1;
		for(int i=1;i<stp;++i)mp[i]=pm[i];
		return;
	}
	if(stp>=ans)return;
	for(int i=1;i<=gs;++i){
		pm[stp]=i;
		dfs(stp+1);
	}
}
void output(apple a){
	cout<<zl[a.lz];
	if(a.lz>=4)printf(" %d",a.zz);
	putchar('\n');
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;++j){
			if(s[i][j]=='S'){
				Spx=i,Spy=j;
			}else if(s[i][j]=='G'){
				Grx=i,Gry=j;
			}
		}
	}
	dfs(1);
	printf("%d\n",ans);
	for(int i=1;i<=ans;++i)output(st[mp[i]]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3880kb

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

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

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

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

input:

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

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

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

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

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

input:

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

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

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

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

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

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

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

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #14:

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

input:

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

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #15:

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

input:

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

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

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

input:

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

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

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

input:

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

output:

4
FORWARD
LEFT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #18:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #19:

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

input:

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

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

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

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #22:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #23:

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

input:

2 4
...S
##G#

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #24:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #25:

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

input:

2 3
#S#
..G

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #26:

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

input:

2 4
#.S#
#G##

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #27:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #28:

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

input:

2 4
S.#.
#G##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #29:

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

input:

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

output:

2
LEFT
FORWARD

result:

ok correct answer!

Test #30:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #31:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

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

input:

3 3
S..
##.
##G

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #33:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #34:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #35:

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

input:

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

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #36:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #37:

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

input:

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

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #38:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #39:

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

input:

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

output:

3
LEFT
FORWARD
FORWARD

result:

ok correct answer!

Test #40:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #41:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
LEFT

result:

ok correct answer!

Test #42:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #43:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #44:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #45:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #46:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #47:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #48:

score: 0
Accepted
time: 8ms
memory: 3804kb

input:

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

output:

4
RIGHT
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #49:

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

input:

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

output:

4
LEFT
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #50:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
IF-OPEN 2

result:

ok correct answer!

Test #51:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #52:

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

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #53:

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

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

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #55:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #56:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #57:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #58:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #59:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #60:

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

input:

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

output:

1
FORWARD

result:

ok correct answer!

Test #61:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #62:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #63:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #64:

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

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: 8ms
memory: 3812kb

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: 3ms
memory: 3828kb

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #67:

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

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #69:

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

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: 9ms
memory: 3816kb

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

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: 3ms
memory: 3816kb

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #73:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #74:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #75:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #76:

score: 0
Accepted
time: 8ms
memory: 3828kb

input:

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

output:

5
LEFT
IF-OPEN 5
RIGHT
GOTO 2
FORWARD

result:

ok correct answer!