sabertooth09

Untitled

Dec 29th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define all(v) v.begin(),v.end()
  5.  
  6. vector<string>s;
  7. char q[]= {'D','U','L','R'};
  8. string path;
  9. vector<string>ques;
  10. int t1,t2;
  11. int qrow,qcol;
  12.  
  13. void init()
  14. {
  15.     int i,j,k,l,we=0;
  16.     string rt="";
  17.     for(i=0; i<4; i++)
  18.     {
  19.         for(j=0; j<4; j++)
  20.         {
  21.             if(j!=i)
  22.             {
  23.                 for(k=0; k<4; k++)
  24.                 {
  25.                     if(k!=i && k!=j)
  26.                     {
  27.                         for(l=0; l<4; l++)
  28.                         {
  29.                             if(l!=i && l!=j && l!=k)
  30.                             {
  31.                                 rt+=q[i];
  32.                                 rt+=q[j];
  33.                                 rt+=q[k];
  34.                                 rt+=q[l];
  35.                                 s.push_back(rt);
  36.                                 rt="";
  37.                             }
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
  45.  
  46. int strt(string x)
  47. {
  48.     for(int i=0; i<x.length(); i++)
  49.     {
  50.         if(x[i]=='S')
  51.             return i;
  52.     }
  53.     return -1;
  54. }
  55.  
  56. bool check(int pos)
  57. {
  58.     int j,i,q,l=0;
  59.     int q2=qcol,q1=qrow;
  60.     bool f=1;
  61.     for(i=0; i<path.length(); i++)
  62.     {
  63.         if(s[pos][path[i]-'0']=='D')
  64.         {
  65.             if(q1+1>=t1 || ques[q1+1][q2]=='#')
  66.             {
  67.                 return 0;
  68.             }
  69.             else
  70.             {
  71.                 q1++;
  72.                 if(ques[q1][q2]=='E')
  73.                     return 1;
  74.             }
  75.         }
  76.         else if(s[pos][path[i]-'0']=='U')
  77.         {
  78.             if(q1-1<0 || ques[q1-1][q2]=='#')
  79.             {
  80.                 return 0;
  81.             }
  82.             else
  83.             {
  84.                 q1--;
  85.                 if(ques[q1][q2]=='E')
  86.                     return 1;
  87.             }
  88.         }
  89.         else if(s[pos][path[i]-'0']=='L')
  90.         {
  91.             if(q2-1<0 || ques[q1][q2-1]=='#')
  92.             {
  93.                 return 0;
  94.             }
  95.             else
  96.             {
  97.                 q2--;
  98.                 if(ques[q1][q2]=='E')
  99.                     return 1;
  100.             }
  101.         }
  102.         else if(s[pos][path[i]-'0']=='R')
  103.         {
  104.             if(q2+1>=t2 || ques[q1][q2+1]=='#')
  105.             {
  106.                 return 0;
  107.             }
  108.             else
  109.             {
  110.                 q2++;
  111.                 if(ques[q1][q2]=='E')
  112.                     return 1;
  113.             }
  114.         }
  115.     }
  116.     return 0;
  117. }
  118. int main()
  119. {
  120.     init();
  121.     string temp;
  122.     int xd;
  123.     cin>>t1>>t2;
  124.     int ans=0;
  125.     for(int i=0; i<t1; i++)
  126.     {
  127.         cin>>temp;
  128.         xd=strt(temp);
  129.         if(xd!=-1)
  130.         {
  131.             qcol=xd;
  132.             qrow=i;
  133.         }
  134.         ques.push_back(temp);
  135.     }
  136.     cin>>path;
  137.     for(int i=0; i<s.size(); i++)
  138.     {
  139.         if(check(i))
  140.             ans++;
  141.     }
  142.     cout<<ans<<endl;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment