QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515336 | #2265. Short Coding | Lavender_Field# | AC ✓ | 389ms | 3948kb | C++20 | 2.6kb | 2024-08-11 17:14:40 | 2024-08-11 17:14:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[15][15];
int pro[10];
vector<int> anspro;
int ans=1000;
int sx,sy,tx,ty;
int px[4]={1,0,-1,0},py[4]={0,-1,0,1};
bool check(int step){
int x=sx,y=sy,dir=0,now=1;
// bool output=0;
// if(pro[1]==11 && pro[2]==12 && step==2) output=1;
for(int i=1;i<=2000;i++){
if(x==tx && y==ty) return 1;
// if(output==1) printf("[%d %d %d]\n",x,y,dir);
if(pro[now]<=5){
if(pro[now]>step || pro[now]==now) return 0;
now=pro[now];
continue;
}
else if(pro[now]<=10){
int k=pro[now]-5;
if(k>step || k==now) return 0;
int xx=x+px[dir],yy=y+py[dir];
if(!(xx<=0 || xx>n || yy<=0 || yy>m ||s[xx][yy]=='#')){
now=k;
continue;
}
}
else if(pro[now]==11){
int xx=x+px[dir],yy=y+py[dir];
if(!(xx<=0 || xx>n || yy<=0 || yy>m ||s[xx][yy]=='#')){
x=xx;y=yy;
}
// printf("%d %d\n",xx)
}
else if(pro[now]==12){
dir=(dir-1+4)%4;
}
else{
dir=(dir+1)%4;
}
now=now%step+1;
}
return 0;
}
void dfs(int step){
if(step-1>ans) return;
if(step>=2 && step-1<ans && check(step-1)){
ans=step-1;anspro.clear();
for(int i=1;i<=step-1;i++){
anspro.push_back(pro[i]);
}
}
if(step==6) return;
for(int i=1;i<=13;i++){
pro[step]=i;
dfs(step+1);
}
}
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;
}
if(s[i][j]=='G'){
tx=i;ty=j;
}
}
}
dfs(1);
if(ans<7){
printf("%d\n",ans);
for(auto x:anspro){
if(x<=5){
printf("GOTO %d\n",x);
}
else if(x<=10){
printf("IF-OPEN %d\n",x-5);
}
else if(x==11){
printf("FORWARD\n");
}
else if(x==12){
printf("LEFT\n");
}
else{
printf("RIGHT\n");
}
}
}
else{
// printf("7\nIF-OPEN 5\nRIGHT\nFORWARD\nIF-OPEN 7\nFORWARD\nGOTO 1\nLEFT\n");
printf("6\nLEFT\nIF-OPEN 1\nRIGHT\nFORWARD\nIF-OPEN 1\nGOTO 3\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 3816kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 11ms
memory: 3944kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 11ms
memory: 3940kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 20ms
memory: 3944kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 20ms
memory: 3948kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 22ms
memory: 3876kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 24ms
memory: 3876kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 20ms
memory: 3792kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 24ms
memory: 3804kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 116ms
memory: 3792kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 131ms
memory: 3940kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 118ms
memory: 3784kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 148ms
memory: 3880kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 115ms
memory: 3880kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 115ms
memory: 3868kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 115ms
memory: 3876kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 116ms
memory: 3888kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 119ms
memory: 3876kb
input:
7 6 ...##S #..... ....#. ...#.# ....#. #..... .....G
output:
4 FORWARD RIGHT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #19:
score: 0
Accepted
time: 148ms
memory: 3788kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 148ms
memory: 3796kb
input:
3 10 ##.......S ####.####. ...#..G##.
output:
4 RIGHT FORWARD LEFT IF-OPEN 2
result:
ok correct answer!
Test #21:
score: 0
Accepted
time: 11ms
memory: 3856kb
input:
2 7 .#S.### .#.G..#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 11ms
memory: 3728kb
input:
2 7 .S#.#.# G#.##.#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 11ms
memory: 3816kb
input:
2 4 ...S ##G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 11ms
memory: 3792kb
input:
2 7 S...... .G.....
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 11ms
memory: 3864kb
input:
2 3 #S# ..G
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 11ms
memory: 3872kb
input:
2 4 #.S# #G##
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 11ms
memory: 3868kb
input:
3 6 .#S### #....# #G.#..
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 11ms
memory: 3748kb
input:
2 4 S.#. #G##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 11ms
memory: 3868kb
input:
2 5 ##..S ...G.
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 11ms
memory: 3788kb
input:
2 9 #S###.... G..##..##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 22ms
memory: 3868kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 20ms
memory: 3788kb
input:
3 3 S.. ##. ##G
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 19ms
memory: 3864kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 18ms
memory: 3784kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 18ms
memory: 3872kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 18ms
memory: 3948kb
input:
4 3 ..S .#. ..# G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 20ms
memory: 3880kb
input:
5 3 S.. ##. ... ... .G.
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 18ms
memory: 3880kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 18ms
memory: 3856kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 18ms
memory: 3944kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 101ms
memory: 3876kb
input:
2 9 .##..S... ##..##G.#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 115ms
memory: 3844kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 86ms
memory: 3752kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 118ms
memory: 3944kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 117ms
memory: 3860kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 86ms
memory: 3796kb
input:
4 3 ..S ... ... #G#
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #47:
score: 0
Accepted
time: 102ms
memory: 3896kb
input:
2 7 #...S.. ..#G##.
output:
4 IF-OPEN 3 RIGHT FORWARD LEFT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 162ms
memory: 3820kb
input:
5 6 ...S.. ...#.. ...#.. ...#.# #G..#.
output:
4 RIGHT FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #49:
score: 0
Accepted
time: 113ms
memory: 3872kb
input:
4 8 .#...#.S ..###... ........ ....G..#
output:
4 FORWARD IF-OPEN 4 LEFT LEFT
result:
ok correct answer!
Test #50:
score: 0
Accepted
time: 98ms
memory: 3756kb
input:
3 4 #S.. ##.. .#G#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 18ms
memory: 3808kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 146ms
memory: 3728kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 338ms
memory: 3868kb
input:
5 5 #.#S# #...# ##.## ##..# .##.G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #54:
score: 0
Accepted
time: 24ms
memory: 3864kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 18ms
memory: 3872kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 18ms
memory: 3812kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 18ms
memory: 3860kb
input:
4 5 S###. .#### .#### ..G##
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 19ms
memory: 3860kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 18ms
memory: 3732kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 10ms
memory: 3860kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 116ms
memory: 3748kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 18ms
memory: 3868kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 14ms
memory: 3864kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 335ms
memory: 3860kb
input:
10 10 ....#S.#.# .#....#... .....#..#. ....#..#.. .#.....#.# .......### #....#.#.. .......... .#.#.##... #....G.#..
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #65:
score: 0
Accepted
time: 247ms
memory: 3868kb
input:
10 10 #...#..#.S .##..#.... ..###.#... ##.##.##.. #.#..##..# .##.##...# ..#.##..#. ...#...##. .#.#....## #.##..G##.
output:
5 GOTO 3 RIGHT FORWARD IF-OPEN 2 LEFT
result:
ok correct answer!
Test #66:
score: 0
Accepted
time: 18ms
memory: 3944kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 334ms
memory: 3876kb
input:
10 10 .....#...S ...#....#. ......#.## ..#......# #.#.##.#.. ..#.##.#.. .......#.. #...#..... #.#....#.. .#...#..#G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #68:
score: 0
Accepted
time: 18ms
memory: 3804kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 275ms
memory: 3860kb
input:
10 10 ......##S. ........#. ....###... ....#.#..# .##....#.# .....#.... .....#.... ..##...... ....#.#.#. .#....G...
output:
5 GOTO 3 LEFT FORWARD IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #70:
score: 0
Accepted
time: 332ms
memory: 3808kb
input:
10 10 #.S#..#... .......#.# #..##..#.# #...#...#. #.###..##. .....#.#.# #.#..#...# ..##.#.#.# ####..#... ##..G#.#.#
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #71:
score: 0
Accepted
time: 336ms
memory: 3912kb
input:
10 10 S#...#.... .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.##. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. ...#...##G
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!
Test #72:
score: 0
Accepted
time: 18ms
memory: 3748kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 136ms
memory: 3752kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 18ms
memory: 3796kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 136ms
memory: 3792kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 389ms
memory: 3736kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 GOTO 4 FORWARD LEFT IF-OPEN 2 RIGHT
result:
ok correct answer!