Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- using namespace std;
- int fx[6]={1,-1,0,0,0,0};
- int fy[6]={0,0,1,-1,0,0};
- int fz[6]={0,0,0,0,1,-1};
- char s[30];
- int vis[4][4][4];
- bool judge(int x,int y,int z)
- {
- if(x<0||x>2||y<0||y>2||z<0||z>2||vis[x][y][z])
- return false;
- return true;
- }
- bool dfs(int x,int y,int z,int icount,int pos)
- {
- char c=s[icount];
- int px = x+fx[pos];
- int py = y+fy[pos];
- int pz = z+fz[pos];
- if(icount==27)
- return judge(px,py,pz);
- if (!judge(px,py,pz))
- return false;
- if(c=='I')
- {
- vis[px][py][pz] = 1;
- if(dfs(px,py,pz,icount+1,pos))
- return true;
- else
- {
- vis[px][py][pz] =0;
- return false;
- }
- }
- else if(c=='L')
- {
- vis[px][py][pz] = 1;
- for (int i=0;i<6;i++)
- {
- if (i!=pos)
- {
- if(dfs(px,py,pz,icount+1,i))
- return true;
- }
- }
- vis[px][py][pz] =0;
- return false;
- }
- }
- int main()
- {
- while(~scanf("%s",s+1))
- {
- memset(vis,0,sizeof(vis));
- bool flag = false;
- for (int i=2;i<27;++i)
- if(s[i]=='E')
- {
- flag = true;
- break;
- }
- if(flag)
- {
- cout<<"NO";
- continue;
- }
- for (int i=0;i<3;++i)
- {
- for (int j=0;j<3;++j)
- {
- for (int k=0;k<3;++k)
- {
- vis[i][j][k]=1;
- if(dfs(i,j,k,2,0))
- {
- flag =true;
- break;
- }
- vis[i][j][k]=0;
- }
- if(flag)
- break;
- }
- if(flag)
- break;
- }
- if(flag)
- cout<<"YES";
- else
- cout<<"NO";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement