QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386489 | #2265. Short Coding | Crysfly | AC ✓ | 1ms | 3868kb | C++17 | 3.7kb | 2024-04-11 17:24:11 | 2024-04-11 17:24:11 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int sx,sy,tx,ty,n,m,k;
char s[12][12];
bool vis[12][12][5][5];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
string op[23]={"","GOTO","IF-OPEN","FORWARD","LEFT","RIGHT"};
int a[23],b[23];
bool isok(int x,int y){
return x>=1 && y>=1 && x<=n && y<=m && s[x][y]!='#';
}
bool chk(){
memset(vis,0,sizeof vis);
int x=sx,y=sy,d=0,i=1;
while(1){
if(vis[x][y][d][i])return 0;
if(x==tx && y==ty)return 1;
vis[x][y][d][i]=1;
int xx=x+dx[d],yy=y+dy[d];
if(a[i]==1) {
i=b[i];
continue;
}
else if(a[i]==2) {
if(isok(xx,yy)) {
i=b[i];
continue;
}
}
else if(a[i]==3){
if(isok(xx,yy)) x=xx,y=yy;
}
else if(a[i]==4)
d=(d+1)%4;
else d=(d+3)%4;
++i;
if(i>k) i=1;
}
}
void dfs(int u){
if(u==k+1){
if(chk()){
cout<<k<<"\n";
For(i,1,k){
if(a[i]<=2) cout<<op[a[i]]<<' '<<b[i]<<"\n";
else cout<<op[a[i]]<<"\n";
}
exit(0);
}
return;
}
For(i,1,2)For(j,1,k)a[u]=i,b[u]=j,dfs(u+1);
For(i,3,5)a[u]=i,dfs(u+1);
}
signed main()
{
n=read(),m=read();
For(i,1,n){
cin>>(s[i]+1);
For(j,1,m){
if(s[i][j]=='S') s[i][j]='.',sx=i,sy=j;
if(s[i][j]=='G') s[i][j]='.',tx=i,ty=j;
}
}
For(i,1,4){
k=i;
dfs(1);
}
puts("5");
puts("LEFT");
puts("IF-OPEN 5");
puts("RIGHT");
puts("GOTO 2");
puts("FORWARD");
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
input:
4 2 S# .# .# G.
output:
1 FORWARD
result:
ok correct answer!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3 6 ##S..# #..##. .G..#.
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3 7 ....S## .#.#... ##.#.G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
4 8 ...S.#.# ##..#.#. ###...#. #.#.#G.#
output:
3 FORWARD FORWARD LEFT
result:
ok correct answer!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
3 5 .S#.. ..... ..#G.
output:
3 FORWARD LEFT FORWARD
result:
ok correct answer!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 10 .....S#... ...#...... ....##.... .#.....#.. ....#..... ..#....... ...#...... .......... .#...#.... G.#..#...#
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #7:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
7 9 .##S.#..# ......... ......... ...#...## ###..#### ........# .....##G#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #8:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 9 ..#.#.#S# #...#...# .G....#.#
output:
3 FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
4 5 #S... ..#.. .#..# .#.G#
output:
3 RIGHT FORWARD FORWARD
result:
ok correct answer!
Test #10:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
6 8 ..S..#.# ...#...# ....#..# #.#.##.. .......# .#..#G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #11:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
9 10 S......... .#..#....# ........#. .......... .....#.#.. .#...#.... #..#.##.#. ..#..#...# ..#.#....G
output:
4 LEFT FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #12:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
10 4 #.S. .#.# ##.# ##.. .#.. #... #.## ..#. .#.. G.##
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #13:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
9 9 #..#...S# .#...##.# .....##.. ..#..#... ..#..#..# .#..#.#.# .###..... ..#.#.##. G#....#.#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #14:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
7 3 .S# #.. ..# ... ..# .#. .G.
output:
4 FORWARD FORWARD FORWARD LEFT
result:
ok correct answer!
Test #15:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
6 6 ..#S.. #.#.#. .....# #.#... ..#... ..G##.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #16:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
6 8 ....#S.. ......#. ..##..#. ###.#.## ..#...#. ##.G#..#
output:
4 FORWARD FORWARD RIGHT FORWARD
result:
ok correct answer!
Test #17:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
10 8 #..S.### .#....## .#...... ....#.#. #...#..# ........ ....#.## ...#.### .#.#...# .#...G.#
output:
4 FORWARD LEFT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #18:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
7 6 ...##S #..... ....#. ...#.# ....#. #..... .....G
output:
4 FORWARD RIGHT FORWARD IF-OPEN 3
result:
ok correct answer!
Test #19:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
4 8 .##..S.. #.###..# .#...#.. ...#G...
output:
4 RIGHT FORWARD FORWARD FORWARD
result:
ok correct answer!
Test #20:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
3 10 ##.......S ####.####. ...#..G##.
output:
4 RIGHT FORWARD LEFT IF-OPEN 2
result:
ok correct answer!
Test #21:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 7 .#S.### .#.G..#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #22:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 7 .S#.#.# G#.##.#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #23:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
2 4 ...S ##G#
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #24:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 7 S...... .G.....
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #25:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
2 3 #S# ..G
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #26:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
2 4 #.S# #G##
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #27:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3 6 .#S### #....# #G.#..
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #28:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
2 4 S.#. #G##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
2 5 ##..S ...G.
output:
2 FORWARD LEFT
result:
ok correct answer!
Test #30:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
2 9 #S###.... G..##..##
output:
2 FORWARD RIGHT
result:
ok correct answer!
Test #31:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
6 10 ....S...## .#...#.... .......... .#.#...#.. ...#.##... .G#...#...
output:
3 LEFT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #32:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 3 S.. ##. ##G
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #33:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 5 ..S.. .##.. .#### ..#.. G.#.#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #34:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
4 6 S#.... ....#. #..... #...G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #35:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3 6 .#..S# ..#..# .##G.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #36:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 3 ..S .#. ..# G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #37:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 3 S.. ##. ... ... .G.
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #38:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
8 2 .S .. .. .. .. .. .# G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #39:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 7 ...#..S #.#.... ....G..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #40:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 9 #......S. ...#.#... .G.#.#...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #41:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
2 9 .##..S... ##..##G.#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #42:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
4 6 S..#.# ..#... ...... ..#G#.
output:
4 FORWARD FORWARD LEFT FORWARD
result:
ok correct answer!
Test #43:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
4 9 #..##S..# ##..#...# #.......# ####.#G##
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #44:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
3 8 ....S... .....#.. ..#G#...
output:
4 FORWARD RIGHT FORWARD LEFT
result:
ok correct answer!
Test #45:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
4 9 .#.S##### ..#.###.. .#....#.# .####.G.#
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #46:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
4 3 ..S ... ... #G#
output:
4 IF-OPEN 3 LEFT LEFT FORWARD
result:
ok correct answer!
Test #47:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
2 7 #...S.. ..#G##.
output:
4 IF-OPEN 3 RIGHT FORWARD LEFT
result:
ok correct answer!
Test #48:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
5 6 ...S.. ...#.. ...#.. ...#.# #G..#.
output:
4 RIGHT FORWARD IF-OPEN 1 RIGHT
result:
ok correct answer!
Test #49:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 8 .#...#.S ..###... ........ ....G..#
output:
4 FORWARD IF-OPEN 4 LEFT LEFT
result:
ok correct answer!
Test #50:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
3 4 #S.. ##.. .#G#
output:
4 IF-OPEN 3 LEFT FORWARD RIGHT
result:
ok correct answer!
Test #51:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
4 6 #.S.#. #..#.. ..#... ..G##.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #52:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
4 5 #..S. #.#.. ..#.. G#..#
output:
4 RIGHT FORWARD LEFT FORWARD
result:
ok correct answer!
Test #53:
score: 0
Accepted
time: 1ms
memory: 3800kb
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: 3632kb
input:
5 6 ##S..# ...#.. ...#.# ...#.. ..#G.#
output:
3 RIGHT FORWARD IF-OPEN 2
result:
ok correct answer!
Test #55:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
6 4 ...S ..#. .... .... .... G...
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #56:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
5 6 ....S. ...... ...... ....#. ....G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #57:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
4 5 S###. .#### .#### ..G##
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #58:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
6 5 ...S. ...#. .#... ..##. .##.. .G#..
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #59:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
5 4 ..S. #... .#.. ..#. G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #60:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
5 5 ..#S# .#..# ....# ..#.# ###G.
output:
1 FORWARD
result:
ok correct answer!
Test #61:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
10 10 #...S..#.. ..#...#... ..#.#.#... ...#....## ##.....#.# .....#.##. .....#...# ...###.... ..#.#..... .#.#....#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #62:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
10 10 .#..S#...# .....#.... ...#...#.# .##..#.... #....###.# ........## ...#..#... ##.#....## ...#....#. #.#G...#.#
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #63:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
10 10 .......S.. .......... .......... .......... ........#. .......... .......... .......... .......... ........G.
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #64:
score: 0
Accepted
time: 1ms
memory: 3632kb
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: 1ms
memory: 3568kb
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: 0ms
memory: 3644kb
input:
10 10 .........S .......... ..#....... .......... .....#.... .#........ .......... .......... .......#.. .G.......#
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #67:
score: 0
Accepted
time: 1ms
memory: 3644kb
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: 0ms
memory: 3572kb
input:
10 10 ......S... .......... .......... .......... .......... ...#....#. .......... #.....#... .......... .....#G...
output:
3 IF-OPEN 3 RIGHT FORWARD
result:
ok correct answer!
Test #69:
score: 0
Accepted
time: 1ms
memory: 3564kb
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: 1ms
memory: 3632kb
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: 1ms
memory: 3572kb
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: 0ms
memory: 3632kb
input:
10 10 S#..#...#. .#.....#.. .#.....#.. .........# ##.#.#.#.. .#.#.#.#.. .#.#.#.#.# .#.#.#.#.. .#.#.#.#.. ...#...#.G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #73:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
10 10 S.#.#.#.#. #..#.#.#.# .#..#.#.#. #.#..#.#.# .#.#..#.#. #.#.#..#.# .#.#.#..#. #.#.#.#..# .#.#.#.#.. #.#.#.#.#G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #74:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
10 10 S......... .########. .#......#. .#......#. .#......#. .#......#. .#......#. .#......#. .########. .........G
output:
3 IF-OPEN 3 LEFT FORWARD
result:
ok correct answer!
Test #75:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# .........G
output:
4 FORWARD LEFT FORWARD RIGHT
result:
ok correct answer!
Test #76:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
10 10 S.#....... #.###.#### #......#.# ##.###.... .#.#...#.# ...#####.# .#.#.#...# .#.#...### ##.#####.# G.........
output:
5 LEFT IF-OPEN 5 RIGHT GOTO 2 FORWARD
result:
ok correct answer!