QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23470#2265. Short CodingThe_NobodyAC ✓42ms3704kbC++142.4kb2022-03-16 15:36:172022-04-30 03:13:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 03:13:40]
  • 评测
  • 测评结果:AC
  • 用时:42ms
  • 内存:3704kb
  • [2022-03-16 15:36:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define Il inline
#define Re register
#define mem(u,v) memset(u,v,sizeof(u))
#define rep(i,a,b) for(Re ll i=(a),KKK##i=(b);i<=KKK##i;i++)
#define drep(i,a,b) for(Re ll i=(a),KKK##i=(b);i>=KKK##i;i--)
#define go(u) for(ll i=head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define _go(u) for(ll i=Head[u],v=E[i].to;i;i=E[i].nxt,v=E[i].to)
#define __go(u) for(ll i=Head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writesp(x) write(x),putchar(' ')
#define writeln(x) write(x),puts("")
using namespace std;
//#define getchar nc
inline char nc(){static char buf[10000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000000,stdin),p1==p2)?EOF:*p1++;}
Il ll read(){ll sum=0,f=0;char ch=getchar();for(;!isdigit(ch);ch=getchar())f|=(ch=='-');for(;isdigit(ch);ch=getchar())sum=((sum<<1)+(sum<<3)+(ch^48));return f?-sum:sum;}
void write(const ll x){if(x<0){putchar('-');write(-x);return;}if(x>9)write(x/10);putchar(x%10+'0');}
char getc(){char c=getchar();while(c!='#'&&c!='.'&&c!='G'&&c!='S')c=getchar();return c;}
#define N 22
string S[15]={"","GOTO 1","GOTO 2","GOTO 3","GOTO 4","GOTO 5","IF-OPEN 1","IF-OPEN 2","IF-OPEN 3","IF-OPEN 4","IF-OPEN 5","LEFT","RIGHT","FORWARD"};
ll n,m,sx,sy,tx,ty,tot=5,ans[7],fx[4]={1,0,-1,0},fy[4]={0,-1,0,1},b[7];char a[N][N];bool vis[12][12][4][7];
bool pd(ll x,ll y){return x>0&&y>0&&x<=n&&y<=m&&a[x][y]!='#';}
bool chk(ll dep){
	mem(vis,0);ll x=sx,y=sy,dir=0,nw=1;
	while(1){
		if(nw>dep)nw=1;
		if(vis[x][y][dir][nw])return 0;
		vis[x][y][dir][nw]=1;
		if(a[x][y]=='G')return 1;
		if(b[nw]<=5){nw=b[nw];if(nw>dep)return 0;continue;}
		if(b[nw]==11){dir--;if(dir<0)dir+=4;nw++;continue;}
		if(b[nw]==12){dir++;if(dir>=4)dir-=4;nw++;continue;}
		if(b[nw]==13){
			ll nx=x+fx[dir],ny=y+fy[dir];
			if(pd(nx,ny))x=nx,y=ny;nw++;
			continue;
		}
		if(b[nw]<=10){
			ll nx=x+fx[dir],ny=y+fy[dir],h=b[nw]-5;
			if(h>dep)return 0;
			if(pd(nx,ny))nw=h;else nw++;
		}
	}
	return 0;
}
void dfs(ll dep){
	if(dep-1>tot)return;
	if(chk(dep-1)){
		if(dep-1<=tot){
			tot=dep-1;
			rep(i,1,dep-1)ans[i]=b[i];
		}
		return;
	}
	rep(i,1,13)b[dep]=i,dfs(dep+1);
}
int main(){
	n=read();m=read();
	rep(i,1,n){
		rep(j,1,m){
			a[i][j]=getc();
			if(a[i][j]=='S')sx=i,sy=j;
		}
	}
	dfs(1);writeln(tot);
//	rep(i,1,tot)cout<<ans[i]<<' ';puts("");
	rep(i,1,tot)cout<<S[ans[i]]<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3600kb

input:

4 2
S#
.#
.#
G.

output:

1
FORWARD

result:

ok correct answer!

Test #2:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #3:

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #4:

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

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #5:

score: 0
Accepted
time: 9ms
memory: 3480kb

input:

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

output:

3
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #6:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #7:

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

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #8:

score: 0
Accepted
time: 9ms
memory: 3700kb

input:

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

output:

3
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #9:

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

input:

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

output:

3
RIGHT
FORWARD
FORWARD

result:

ok correct answer!

Test #10:

score: 0
Accepted
time: 36ms
memory: 3480kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #11:

score: 0
Accepted
time: 27ms
memory: 3596kb

input:

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

output:

4
LEFT
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #12:

score: 0
Accepted
time: 37ms
memory: 3608kb

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #13:

score: 0
Accepted
time: 31ms
memory: 3652kb

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #14:

score: 0
Accepted
time: 33ms
memory: 3496kb

input:

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

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #15:

score: 0
Accepted
time: 35ms
memory: 3552kb

input:

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

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #16:

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

input:

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

output:

4
FORWARD
FORWARD
RIGHT
FORWARD

result:

ok correct answer!

Test #17:

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

input:

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

output:

4
FORWARD
LEFT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #18:

score: 0
Accepted
time: 36ms
memory: 3692kb

input:

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

output:

4
FORWARD
RIGHT
FORWARD
IF-OPEN 3

result:

ok correct answer!

Test #19:

score: 0
Accepted
time: 34ms
memory: 3548kb

input:

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

output:

4
RIGHT
FORWARD
FORWARD
FORWARD

result:

ok correct answer!

Test #20:

score: 0
Accepted
time: 30ms
memory: 3556kb

input:

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

output:

4
RIGHT
FORWARD
LEFT
IF-OPEN 2

result:

ok correct answer!

Test #21:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #22:

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

input:

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

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #23:

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

input:

2 4
...S
##G#

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #24:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #25:

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

input:

2 3
#S#
..G

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #26:

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

input:

2 4
#.S#
#G##

output:

2
FORWARD
LEFT

result:

ok correct answer!

Test #27:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #28:

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

input:

2 4
S.#.
#G##

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #29:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #30:

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

input:

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

output:

2
FORWARD
RIGHT

result:

ok correct answer!

Test #31:

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

input:

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

output:

3
LEFT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #32:

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

input:

3 3
S..
##.
##G

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #33:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #34:

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

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #35:

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

input:

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

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #36:

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

input:

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

output:

3
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #37:

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

input:

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

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #38:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #39:

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

input:

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

output:

3
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #40:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #41:

score: 0
Accepted
time: 22ms
memory: 3528kb

input:

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

output:

4
FORWARD
FORWARD
FORWARD
RIGHT

result:

ok correct answer!

Test #42:

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

input:

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

output:

4
FORWARD
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #43:

score: 0
Accepted
time: 22ms
memory: 3596kb

input:

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

output:

4
FORWARD
IF-OPEN 4
LEFT
LEFT

result:

ok correct answer!

Test #44:

score: 0
Accepted
time: 37ms
memory: 3600kb

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #45:

score: 0
Accepted
time: 31ms
memory: 3596kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #46:

score: 0
Accepted
time: 22ms
memory: 3704kb

input:

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

output:

4
FORWARD
IF-OPEN 4
RIGHT
RIGHT

result:

ok correct answer!

Test #47:

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

input:

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

output:

4
FORWARD
FORWARD
FORWARD
LEFT

result:

ok correct answer!

Test #48:

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

input:

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

output:

4
RIGHT
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #49:

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

input:

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

output:

4
FORWARD
RIGHT
FORWARD
LEFT

result:

ok correct answer!

Test #50:

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

input:

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

output:

4
LEFT
FORWARD
RIGHT
IF-OPEN 2

result:

ok correct answer!

Test #51:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #52:

score: 0
Accepted
time: 34ms
memory: 3704kb

input:

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

output:

4
RIGHT
FORWARD
LEFT
FORWARD

result:

ok correct answer!

Test #53:

score: 0
Accepted
time: 36ms
memory: 3704kb

input:

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

output:

5
FORWARD
RIGHT
IF-OPEN 1
RIGHT
RIGHT

result:

ok correct answer!

Test #54:

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

input:

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

output:

3
RIGHT
FORWARD
IF-OPEN 2

result:

ok correct answer!

Test #55:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #56:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #57:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #58:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #59:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #60:

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

input:

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

output:

1
FORWARD

result:

ok correct answer!

Test #61:

score: 0
Accepted
time: 31ms
memory: 3700kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #62:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #63:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #64:

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

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

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #67:

score: 0
Accepted
time: 36ms
memory: 3548kb

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #69:

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

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

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

input:

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

output:

5
FORWARD
RIGHT
IF-OPEN 1
RIGHT
RIGHT

result:

ok correct answer!

Test #72:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
LEFT

result:

ok correct answer!

Test #73:

score: 0
Accepted
time: 27ms
memory: 3548kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #74:

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

input:

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

output:

3
FORWARD
IF-OPEN 1
RIGHT

result:

ok correct answer!

Test #75:

score: 0
Accepted
time: 31ms
memory: 3576kb

input:

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

output:

4
FORWARD
LEFT
FORWARD
RIGHT

result:

ok correct answer!

Test #76:

score: 0
Accepted
time: 42ms
memory: 3560kb

input:

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

output:

5
FORWARD
RIGHT
IF-OPEN 1
RIGHT
RIGHT

result:

ok correct answer!