fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. #define ull unsigned long long
  5. #define mod 1000000007
  6. #define pb push_back
  7. const int N =2010;
  8. int n,m,sti,stj,ll,rr,vis[N][N];
  9. char g[N][N];
  10. void bfs()
  11. {
  12. deque<pair<pair<int,int>,pair<int,int>>>q;
  13. q.push_front({{sti,stj},{ll,rr}});
  14. vis[sti][stj]=1;
  15. while(!q.empty())
  16. {
  17. int i=q.front().first.first;
  18. int j= q.front().first.second;
  19. int l= q.front().second.first;
  20. int r= q.front().second.second;
  21. q.pop_front();
  22. int k=l;
  23. for(int x=j-1;x>0;x--)
  24. {
  25. if(k==0) break;
  26. k--;
  27. if(!vis[i][x] && g[i][x]!= '*')
  28. {
  29. q.pb({{i,x},{k,r}});
  30. vis[i][x]=1;
  31. }
  32. else break;
  33. }
  34. k=r;
  35. for(int x=j+1;x<=m;x++)
  36. {
  37. if(k==0) break;
  38. k--;
  39. if(!vis[i][x] && g[i][x]!= '*')
  40. {
  41. q.pb({{i,x},{l,k}});
  42. vis[i][x]=1;
  43. }
  44. else break;
  45. }
  46. k=i-1;
  47. while(k>0)
  48. {
  49. if(g[k][j]=='*' || vis[k][j]) break;
  50. q.push_front({{k,j},{l,r}});
  51. vis[k][j]=1;
  52. k--;
  53. }
  54. k=i+1;
  55. while(k<=n)
  56. {
  57. if(g[k][j]=='*' || vis[k][j]) break;
  58. q.push_front({{k,j},{l,r}});
  59. vis[k][j]=1;
  60. k++;
  61. }
  62. }
  63. }
  64. int main()
  65. {
  66. ios::sync_with_stdio(0);
  67. cin.tie(0);
  68. cout.tie(0);
  69. cin >> n >>m >> sti >> stj >>ll >>rr;
  70. for(int i=1;i<=n;i++)
  71. {
  72. for(int j=1;j<=m;j++)
  73. cin >> g[i][j];
  74. }
  75. bfs();
  76. int cnt=0;
  77. for(int i=1;i<=n;i++)
  78. {
  79. for(int j=1;j<=m;j++)
  80. {
  81. if(vis[i][j])
  82. cnt++;
  83. }
  84. }
  85. cout << cnt;
  86. }
  87.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty