QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668155 | #2345. Karel the Robot | zrzzrz | TL | 5ms | 5852kb | C++14 | 2.8kb | 2024-10-23 11:59:40 | 2024-10-23 11:59:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int r,c,d,e,x,y;
char Mp[45][45],h,t[105],s[30][105],T[105];
unordered_map<char,char> turn_l;
unordered_map<char,int> dx,dy;
struct Node{
int x,y;
char h;
string s;
bool operator<(const Node &T)const{
if (x!=T.x) return x<T.x;
if (y!=T.y) return y<T.y;
if (h!=T.h) return h<T.h;
return s<T.s;
}
};
map<Node,int> cnt;
queue<Node> q;
bool is_b(){
return Mp[x+dx[h]][y+dy[h]]!='.';
}
string get(string t,int l,int r){
string res="";
for (int i=l;i<=r;i++) res+=t[i];
return res;
}
bool work(string t){
if (!t.size()) return 1;
Node t0={x,y,h,t};
q.push(t0);
if (cnt[t0]>1000) return 0;
cnt[t0]++;
bool Flag=1;
if (t[0]=='m'){
if (!is_b()) x+=dx[h],y+=dy[h];
Flag&=work(get(t,1,t.size()-1));
}
if (t[0]=='l'){
h=turn_l[h];
Flag&=work(get(t,1,t.size()-1));
}
if (t[0]>='A'&&t[0]<='Z'){
Flag&=work(s[t[0]-'A']);
Flag&=work(get(t,1,t.size()-1));
}
if (t[0]=='i'){
int cnt=0,len=t.size(),tot=0,p;
char ch=t[1];
string T="";
char h0=h;
bool B=is_b();
for (int i=2;i<len;i++){
if (t[i]=='('){
cnt++;
if (cnt>1) T+=t[i];
}
else if (t[i]==')'){
cnt--;
if (cnt) T+=t[i];
}
else if (cnt) T+=t[i];
if (t[i]==')'&&!cnt){
if ((ch=='b'&&B||h0==ch&&ch!='b')&&!tot) Flag&=work(T);
if (!(ch=='b'&&B||h0==ch&&ch!='b')&&tot) Flag&=work(T);
tot++,T="";
if (tot==2){p=i;break;}
}
}
for (int i=p+1;i<len;i++) T+=t[i];
Flag&=work(T);
}
if (t[0]=='u'){
char ch=t[1];
string T="";
int len=t.size(),cnt=0,p;
for (int i=2;i<len;i++){
if (t[i]=='('){
cnt++;
if (cnt>1) T+=t[i];
}
else if (t[i]==')'){
cnt--;
if (cnt) T+=t[i];
else{p=i;break;}
}
else if (cnt) T+=t[i];
}
while (!(ch=='b'&&is_b()||h==ch&&ch!='b')) if (!work(T)){Flag=0;break;}
T="";
for (int i=p+1;i<len;i++) T+=t[i];
Flag&=work(T);
}
return Flag;
}
int main(){
turn_l['n']='w',dx['n']=-1,dy['n']=0;
turn_l['w']='s',dx['w']=0,dy['w']=-1;
turn_l['s']='e',dx['s']=1,dy['s']=0;
turn_l['e']='n',dx['e']=0,dy['e']=1;
scanf("%d%d%d%d",&r,&c,&d,&e);
for (int i=1;i<=r;i++) for (int j=1;j<=c;j++) scanf(" %c",&Mp[i][j]);
for (int i=1;i<=d;i++){
char c;
scanf(" %c=",&c);
cin>>s[c-'A'];
}
for (int i=1;i<=e;i++){
scanf("%d%d %c",&x,&y,&h),cin>>t;
if (!work(t)) puts("inf");
else printf("%d %d %c\n",x,y,h);
while (!q.empty()) cnt[q.front()]=0,q.pop();
}
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 5ms
memory: 5852kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 4060kb
Test #3:
score: 0
Accepted
time: 1ms
memory: 4024kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3772kb
Test #5:
score: 0
Accepted
time: 2ms
memory: 4604kb
Test #6:
score: -100
Time Limit Exceeded