fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool vis[101][101];
  4. vector<string> split_string(string);
  5.  
  6. bool safe(int x,int y,vector<string>&grid)
  7. {
  8. if(x>=0 && y>=0 && x<grid.size() && y<grid.size() && vis[x][y]==false && grid[x][y]=='.')
  9. {
  10. vis[x][y]=true;
  11. return true;
  12. }
  13.  
  14. return false;
  15. }
  16.  
  17.  
  18. int minimumMoves(vector<string> grid, int startX, int startY, int goalX, int goalY)
  19. {
  20. int i,j,k,ans,t,x,y,xx,yy;
  21. int f=0;
  22. memset(vis,false,sizeof(vis));
  23. ans=1;
  24. queue<pair<int,int>>q;
  25. pair<int,int>p;
  26.  
  27. if(startX==goalX && startY==goalY || grid.size()==1)
  28. return 0;
  29.  
  30.  
  31. q.push({startX,startY});
  32. vis[startX][startY]=true;
  33.  
  34.  
  35. while(!q.empty())
  36. {
  37. t=q.size();
  38.  
  39. while(t--)
  40. {
  41. p=q.front();
  42. q.pop();
  43. x=p.first;
  44. y=p.second;
  45. xx=x;
  46. yy=y;
  47.  
  48. while(safe(xx+1,yy,grid))
  49. {
  50. xx=xx+1;
  51. q.push({xx,yy});
  52.  
  53. if(xx==goalX && yy==goalY)
  54. return ans;
  55. }
  56.  
  57.  
  58. xx=p.first;
  59. yy=p.second;
  60.  
  61.  
  62. while(safe(xx-1,yy,grid))
  63. {
  64.  
  65. xx=xx-1;
  66. q.push({xx,yy});
  67. if(xx==goalX && yy==goalY)
  68. return ans;
  69. }
  70.  
  71.  
  72.  
  73. xx=p.first;
  74. yy=p.second;
  75.  
  76. while(safe(xx,yy+1,grid))
  77. {
  78. yy=yy+1;
  79. q.push({xx,yy});
  80. if(xx==goalX && yy==goalY)
  81. return ans;
  82. }
  83.  
  84.  
  85. xx=p.first;
  86. yy=p.second;
  87.  
  88.  
  89. while(safe(xx,yy-1,grid))
  90. {
  91.  
  92. yy=yy-1;
  93. q.push({xx,yy});
  94. if(xx==goalX && yy==goalY)
  95. return ans;
  96. }
  97.  
  98.  
  99. }
  100. ans+=1;
  101.  
  102. }
  103.  
  104. return 0;
  105.  
  106. }
  107.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty