QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#663054 | #2345. Karel the Robot | Coffins | WA | 217ms | 362996kb | C++14 | 3.6kb | 2024-10-21 12:24:37 | 2024-10-21 12:24:38 |
Judging History
answer
//10:18
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
const int N=45;
int n,m,k,q,cnt;
int a[N][N];
map<char,string> trs;
map<char,int> dir;
int mx[4]={-1,0,1,0};
int my[4]={0,-1,0,1};
char dr[4]={'n','w','s','e'};
struct Node
{
int x,y,d;
Node(int i,int j,int k)
:x(i),y(j),d(k){}
Node(){x=y=d=0;}
};Node dfs(int x,int y,int d,string s)
{
int nx=x+mx[d],ny=y+my[d];
int lt=s.length();cnt++;
if(cnt>1e6)return Node(-1,-1,-1);
for(int i=0;i<lt;i++)
{
if(s[i]=='m')
{
if(a[nx][ny])x=nx,y=ny;
nx=x+mx[d],ny=y+my[d];
}
else if(s[i]=='l')
{
d=(d+1)%4;
nx=x+mx[d],ny=y+my[d];
}
else if(s[i]>='A'&&s[i]<='Z')
{
Node ps=dfs(x,y,d,trs[s[i]]);
if(ps.x==-1)return ps;
x=ps.x,y=ps.y,d=ps.d;
nx=x+mx[d],ny=y+my[d];
}
else if(s[i]=='i')
{
i++;int l1=0,r1=0,l2=0,r2=0,ct=0;
for(int j=i+1;j<lt;j++)
{
if(s[j]=='(')
{
ct++;
if(ct==1)
{
if(!l1)l1=j;
else if(!l2)l2=j;
}
}
if(s[j]==')')
{
ct--;
if(ct==0)
{
if(!r1)r1=j;
else{r2=j;break;}
}
}
}string t0="",t1="",t;
for(int j=l1+1;j<=r1-1;j++)t0+=s[j];
for(int j=l2+1;j<=r2-1;j++)t1+=s[j];
if(s[i]=='b')
{
if(!a[nx][ny])
t=t0;else t=t1;
}else
{
if(dir[s[i]]==d)
t=t0;else t=t1;
}i=r2;Node ps=dfs(x,y,d,t);
if(ps.x==-1)return ps;
x=ps.x,y=ps.y,d=ps.d;
nx=x+mx[d],ny=y+my[d];
}
else if(s[i]=='u')
{
i++;int l=0,r=0,ct=0;
for(int j=i+1;j<lt;j++)
{
if(s[j]=='(')
{
ct++;
if(ct==1)l=j;
}if(s[j]==')')
{
ct--;
if(ct==0){r=j;break;}
}
}string t="";
for(int j=l+1;j<=r-1;j++)t+=s[j];
while(1)
{
if(s[i]=='b'){if(!a[nx][ny])break;}
else{if(dir[s[i]]==d)break;}
Node ps=dfs(x,y,d,t);
if(ps.x==-1)return ps;
x=ps.x,y=ps.y,d=ps.d;
nx=x+mx[d],ny=y+my[d];
}i=r;
}
}return Node(x,y,d);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m>>k>>q;
dir['n']=0,dir['w']=1,
dir['s']=2,dir['e']=3;
for(int i=1;i<=n;i++)
{
string s;cin>>s;
for(int j=1;j<=m;j++)
a[i][j]=(s[j-1]=='.');
}for(int i=1;i<=k;i++)
{
string str,t="";cin>>str;
int len=str.length();
for(int i=2;i<len;i++)t+=str[i];
trs[str[0]]=t;
}for(int i=1;i<=q;i++)
{
int x,y,d;string s;
cnt=0;cin>>x>>y>>s;
d=dir[s[0]];cnt=0;
cin>>s;Node nd=dfs(x,y,d,s);
if(nd.x==-1)cout<<"inf\n";
else cout<<nd.x<<' '<<nd.y<<' '<<dr[nd.d]<<'\n';
}return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 72ms
memory: 362920kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
Test #3:
score: 0
Accepted
time: 18ms
memory: 3540kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
Test #5:
score: 0
Accepted
time: 217ms
memory: 362996kb
Test #6:
score: -100
Wrong Answer
time: 180ms
memory: 3624kb