fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. typedef long long ll;
  5. int freq[27];
  6. char arr[2005][2005];
  7. int node[2005][2005];
  8. int vis[2005][2005];
  9. int dx[4]={1,-1,0,0};
  10. int dy[4]={0,0,1,-1};
  11. int n,m,r,c,x,y;
  12. int gc,gr;
  13. int valid(int x,int y)
  14. {
  15. if(x<0 || y<0 || x>=n || y>=m)
  16. {
  17. return 0;
  18. }
  19. if(arr[x][y]=='*')
  20. return 0;
  21. return 1;
  22. }
  23. void fun(int x,int y)
  24. {
  25. queue<pair<int,pair<int,pair<int,int > > > >q;
  26. q.push({x,{y,{r,c}}});
  27.  
  28. while(!q.empty())
  29. {
  30. pair<int,pair<int,pair<int,int> > >p = q.front();
  31. int cx = p.first;
  32. int cy = p.second.first;
  33. int cr = p.second.second.first;
  34. int cc = p.second.second.second;
  35.  
  36. if(arr[cx][cy]=='*')
  37. {
  38. q.pop();
  39. continue;
  40. }
  41. if(cr==0 && cc==0)
  42. {
  43. node[cx][cy]=1;
  44. q.pop();
  45. continue;
  46. }
  47. vis[cx][cy]=1;
  48. q.pop();
  49. int X,Y;
  50. X = cx+1;
  51. Y = cy;
  52. if(valid(X,Y) && !vis[X][Y]&& node[X][Y]==0)
  53. {
  54. if(cr!=0 || cc!=0)
  55. q.push({X,{Y,{cr,cc}}});
  56. if(cr>=0 && cc>=0)
  57. {
  58. node[X][Y]=1;
  59. }
  60. }
  61. X=cx-1;
  62. Y=cy;
  63. if(valid(X,Y) && !vis[X][Y]&& node[X][Y]==0)
  64. {
  65. if(cr!=0 || cc!=0)
  66. q.push({X,{Y,{cr,cc}}});
  67. if(cr>=0 && cc>=0)
  68. {
  69. node[X][Y]=1;
  70. }
  71. }
  72. X=cx;
  73. Y=cy-1;
  74. if(valid(X,Y) && !vis[X][Y]&& node[X][Y]==0)
  75. {
  76. if(cr!=0 || cc!=0)
  77. q.push({X,{Y,{cr-1,cc}}});
  78. if(cr>=1 && cc>=0)
  79. {
  80. node[X][Y]=1;
  81. }
  82. }
  83. X=cx;
  84. Y=cy+1;
  85. if(valid(X,Y) && !vis[X][Y] && node[X][Y]==0)
  86. {
  87. if(cr!=0 || cc!=0)
  88. q.push({X,{Y,{cr,cc-1}}});
  89.  
  90. if(cr>=0 && cc>=1)
  91. {
  92. node[X][Y]=1;
  93. }
  94. }
  95.  
  96. }
  97. }
  98. int main()
  99. {
  100. ios_base::sync_with_stdio(false);
  101. cin.tie(NULL);
  102. cin>>n>>m;
  103. cin>>x>>y;
  104. gr=r;
  105. gc=c;
  106. cin>>r>>c;
  107. for(int i=0;i<n;i++)
  108. {
  109. for(int j=0;j<m;j++)
  110. {
  111. cin>>arr[i][j];
  112. }
  113. }
  114. x--;y--;
  115.  
  116. fun(x,y);
  117. int cnt=0;
  118. for(int i=0;i<n;i++)
  119. {
  120. for(int j=0;j<m;j++)
  121. {
  122. if(node[i][j]==1)
  123. {
  124. cnt++;
  125. // cout<<i<<" "<<j<<endl;
  126. }
  127. }
  128. }
  129. cout<<cnt+1<<endl;
  130. }
  131.  
Success #stdin #stdout 0s 50568KB
stdin
Standard input is empty
stdout
1