QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667974 | #2345. Karel the Robot | _CLY_ | WA | 1ms | 3744kb | C++17 | 2.9kb | 2024-10-23 10:17:07 | 2024-10-23 10:17:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
long long x=0; char ch; bool f=0;
while(((ch=getchar())<'0'||ch>'9')&&ch!='-') ;
if(ch=='-') f=1;
else x=ch^48;
while((ch=getchar())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48);
return f?-x:x;
}
const int N=45;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int n,m,k1,k2;
char a[N][N];
map<string,int> fx;
string s[N];
map<char,int> rk;
char zh(int x){
if(!x) return 'n';
else if(x==1) return 's';
else if(x==2) return 'w';
else return 'e';
}
int lt(int x){
if(!x) return 2;
if(x==2) return 1;
if(x==1) return 3;
if(x==3) return 0;
}
int x,y,f;
int bzif;
int ok(int x,int y){
return x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]!='#';
}
struct node{
int x,y,f;
string v;
bool operator<(const node &t)const{
if(x^t.x) return x<t.x;
if(y^t.y) return y<t.y;
if(f^t.f) return f<t.f;
if(v.size()!=t.v.size()) return v.size()<t.v.size();
return v<t.v;
}
};
map<node,int> mp;
int R;
pair<string,int> get(string cz,int fi){
string t="";
int c=0,i=fi;
for(i=fi;;i++){
assert(i<cz.size());
if(cz[i]=='('){
c++;
}
if(cz[i]==')'){
c--;
if(!c) break;
}
if(i!=fi) t+=cz[i];
}
return {t,i};
}
void op(string cz){
// cout<<cz<<"??"<<x<<" "<<y<<" "<<f<<"\n";
if(mp[{x,y,f,cz}]||bzif){
bzif=1; return;
}
if(!cz.size()) return;
mp[{x,y,f,cz}]=1;
for(int i=0;i<cz.size()&&!bzif;){
if(cz[i]=='m'){
if(ok(x+dx[f],y+dy[f])) x+=dx[f],y+=dy[f];
i++;
// cerr<<i<<"!\n";
}
else if(cz[i]=='l'){
f=lt(f);
i++;
}
else if(cz[i]=='u'){
string ck=""; ck+=cz[i+1];
pair<string,int> tn=get(cz,i+2);
string nex=tn.first;
// cerr<<ck<<"??\n";
if(ck=="b"){
while(ok(x+dx[f],y+dy[f])&&!bzif){
op(nex);
}
}
else{
while(f!=fx[ck]&&!bzif){
op(nex);
}
}
i=tn.second;
i++;
}
else if(cz[i]=='i'){
string ck=""; ck+=cz[i+1];
pair<string,int> t1=get(cz,i+2);
string ne1=t1.first;
i=t1.second;
i++;
pair<string,int> t2=get(cz,i);
string ne2=t2.first;
i=t2.second;
if(ck=="b"){
if(!ok(x+dx[f],y+dy[f])) op(ne1);
else op(ne2);
}
else{
if(f==fx[ck]) op(ne1);
else op(ne2);
}
i++;
}
else if('A'<=cz[i]&&cz[i]<='Z'&&rk[cz[i]]){
op(s[rk[cz[i]]]); i++;
}
else i++;
}
}
int main(){
// freopen("t1.in","r",stdin);
// freopen("t1.out","w",stdout);
fx["n"]=0,fx["s"]=1,fx["w"]=2,fx["e"]=3;
n=read(),m=read(),k1=read(),k2=read();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) scanf(" %c",&a[i][j]);
}
for(int i=1;i<=k1;i++){
string S; cin>>S;
rk[S[0]]=i;
for(int j=2;j<S.size();j++) s[i]+=S[j];
}
while(k2--){
x=read(),y=read(); string c; cin>>c; f=fx[c];
bzif=0;
string cz; cin>>cz;
mp.clear();
op(cz);
if(bzif) puts("inf");
else cout<<x<<" "<<y<<" "<<zh(f)<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 3624kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 3636kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3692kb
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3744kb