fork(1) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <map>
  4. #define con dfs(store[c].x,store[c].y,1,mars)
  5. #define con1 x+dirx[c]<=co&&x+dirx[c]>=0&&y+diry[c]<=r&&y+diry[c]>=0&&graph[y+diry[c]][x+dirx[c]]==po[len]&&mars[x+dirx[c]][y+diry[c]]==false
  6. using namespace std;
  7. map<int,map<int,char> >graph;
  8.  
  9. struct node{int x,y;};
  10. int r,co;
  11. const char po[]={'A','L','L','I','Z','Z','W','E','L','L'};
  12. int dirx[]={0,0, 1, 1,1,-1,-1,-1};
  13. int diry[]={1,-1,1,-1,0,1,-1,0};
  14. int dfs(int x,int y,int len,map<int,map<int,bool> > mars){
  15. mars[x][y]=true;
  16. int o(-1);
  17. for (int c(0);c<8;c++){
  18. // cout << x+dirx[c] << " " << y+diry[c] << " " << mars[x+dirx[c]][y+diry[c]] << " " << (con1)<< endl;
  19. if (len==9&&con1)return 1; else if (len==9)continue;
  20. if (con1){o=dfs(x+dirx[c],y+diry[c],len+1,mars);}
  21. }
  22.  
  23.  
  24. return o;
  25. }
  26. int main()
  27. {
  28. int t;
  29. cin >> t;
  30. for (;t>0;t--){
  31. graph.clear();
  32. node store[10000];
  33. int current(0);
  34. cin >> r >> co;
  35. for (int c(0);c<r;c++)
  36. {
  37. string a;cin >> a;
  38.  
  39. for (int c1(0);c1<co;c1++)
  40. {
  41.  
  42.  
  43. graph[c][c1]=a[c1];
  44. if (graph[c][c1]=='A'){
  45.  
  46. store[current].x=c1;store[current].y=c;current++;
  47. }
  48. }
  49. }
  50. int flag(0);map<int,map<int,bool> > mars;
  51. for (int c(0);c<=current;c++){
  52. int result=con;
  53.  
  54. if (result==1){flag=1;printf("YES\n\n");break;}
  55. }
  56. if (flag!=1)printf("NO\n\n");
  57. }
  58.  
  59. return 0;
  60. }
  61.  
  62.  
Success #stdin #stdout 0.01s 3492KB
stdin
5

3 6

AWE.QX

LLL.EO

IZZWLL



1 10

ALLIZZWELL



2 9

A.L.Z.E..

.L.I.W.L.



3 3

AEL

LWZ

LIZ



1 10

LLEWZZILLA
stdout
YES

YES

NO

NO

YES