Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define all(v) v.begin(),v.end()
- vector<string>s;
- char q[]= {'D','U','L','R'};
- string path;
- vector<string>ques;
- int t1,t2;
- int qrow,qcol;
- void init()
- {
- int i,j,k,l,we=0;
- string rt="";
- for(i=0; i<4; i++)
- {
- for(j=0; j<4; j++)
- {
- if(j!=i)
- {
- for(k=0; k<4; k++)
- {
- if(k!=i && k!=j)
- {
- for(l=0; l<4; l++)
- {
- if(l!=i && l!=j && l!=k)
- {
- rt+=q[i];
- rt+=q[j];
- rt+=q[k];
- rt+=q[l];
- s.push_back(rt);
- rt="";
- }
- }
- }
- }
- }
- }
- }
- }
- int strt(string x)
- {
- for(int i=0; i<x.length(); i++)
- {
- if(x[i]=='S')
- return i;
- }
- return -1;
- }
- bool check(int pos)
- {
- int j,i,q,l=0;
- int q2=qcol,q1=qrow;
- bool f=1;
- for(i=0; i<path.length(); i++)
- {
- if(s[pos][path[i]-'0']=='D')
- {
- if(q1+1>=t1 || ques[q1+1][q2]=='#')
- {
- return 0;
- }
- else
- {
- q1++;
- if(ques[q1][q2]=='E')
- return 1;
- }
- }
- else if(s[pos][path[i]-'0']=='U')
- {
- if(q1-1<0 || ques[q1-1][q2]=='#')
- {
- return 0;
- }
- else
- {
- q1--;
- if(ques[q1][q2]=='E')
- return 1;
- }
- }
- else if(s[pos][path[i]-'0']=='L')
- {
- if(q2-1<0 || ques[q1][q2-1]=='#')
- {
- return 0;
- }
- else
- {
- q2--;
- if(ques[q1][q2]=='E')
- return 1;
- }
- }
- else if(s[pos][path[i]-'0']=='R')
- {
- if(q2+1>=t2 || ques[q1][q2+1]=='#')
- {
- return 0;
- }
- else
- {
- q2++;
- if(ques[q1][q2]=='E')
- return 1;
- }
- }
- }
- return 0;
- }
- int main()
- {
- init();
- string temp;
- int xd;
- cin>>t1>>t2;
- int ans=0;
- for(int i=0; i<t1; i++)
- {
- cin>>temp;
- xd=strt(temp);
- if(xd!=-1)
- {
- qcol=xd;
- qrow=i;
- }
- ques.push_back(temp);
- }
- cin>>path;
- for(int i=0; i<s.size(); i++)
- {
- if(check(i))
- ans++;
- }
- cout<<ans<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment