Advertisement
VladNitu

lee

Dec 10th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #pragma once
  2. #define NMAX 2001
  3. #define ll long long
  4. #define MOD (int)(1e9 + 7)
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. ifstream f ("01A.in");
  8. ofstream g ("01A.out");
  9.  
  10. struct hash_pair {
  11. template <class T1, class T2>
  12. size_t operator()(const pair<T1, T2>& p) const
  13. {
  14. auto hash1 = hash<T1>{}(p.first);
  15. auto hash2 = hash<T2>{}(p.second);
  16.  
  17. if (hash1 != hash2) {
  18. return hash1 ^ hash2;
  19. }
  20.  
  21. // If hash1 == hash2, their XOR is zero.
  22. return hash1;
  23. }
  24. };
  25.  
  26. struct gnome {
  27. int x, y, left_a, left_b;
  28. };
  29. ll ans = 0;
  30. int T;
  31. int N, M;
  32. int x,y;
  33. int a,b;
  34. bool viz[NMAX][NMAX];
  35. int m[NMAX][NMAX];
  36. char ch;
  37. const vector<int> dx {-1, 1, 0, 0};
  38. const vector<int> dy {0, 0, -1, 1};
  39. //jos, sus, st., dr.
  40.  
  41. bool valid (int i, int j) {
  42. return (i >= 1 && i <= N && j >= 1 && j <= M && m[i][j] != -1);
  43. }
  44.  
  45. int main() { // O(N*M) Lee
  46.  
  47. cin >> N >> M;
  48. cin >> x >> y;
  49. viz[x][y] = true;
  50. cin >> b >> a;
  51.  
  52. for (int i = 1; i <= N; ++i)
  53. for (int j = 1; j <= M; ++j)
  54. {
  55. cin >> ch;
  56. if (ch == '_')
  57. m[i][j] = 0;
  58. else
  59. m[i][j] = -1;
  60. }
  61.  
  62.  
  63. queue<gnome> Q;
  64. Q.push({x, y, a, b});
  65.  
  66. while (!Q.empty()) {
  67. gnome G = Q.front();
  68. Q.pop();
  69.  
  70. for (int i = 0; i < 2; ++i) //sus & jos
  71. {
  72. int xx = G.x + dx[i];
  73. int yy = G.y + dy[i];
  74. if (valid(xx, yy) && !viz[xx][yy])
  75. {
  76. viz[xx][yy] = true;
  77. Q.push({xx, yy, G.left_a, G.left_b});
  78. }
  79.  
  80. }
  81.  
  82. // st.
  83. int xx = G.x + dx[2];
  84. int yy = G.y + dy[2];
  85. if (valid(xx, yy) && !viz[xx][yy] && G.left_b > 0)
  86. {
  87. viz[xx][yy] = true;
  88. Q.push({xx, yy, G.left_a, G.left_b - 1});
  89. }
  90.  
  91. //dr.
  92. xx = G.x + dx[3];
  93. yy = G.y + dy[3];
  94. if (valid(xx, yy) && !viz[xx][yy] && G.left_a > 0)
  95. {
  96. viz[xx][yy] = true;
  97. Q.push({xx, yy, G.left_a - 1, G.left_b});
  98. }
  99.  
  100.  
  101. }
  102.  
  103. for (int i = 1; i <= N; ++i)
  104. for (int j = 1; j <= M; ++j)
  105. if (viz[i][j])
  106. {
  107. g << i << ' ' << j << '\n';
  108. ans ++;
  109. }
  110. cout << ans << '\n';
  111.  
  112. return 0;
  113. }
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement