ProgMe

Untitled

Jun 7th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. //#define FILE 10
  6. #define int int64_t
  7.  
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10.  
  11. template<typename T>
  12. using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  13. template<typename T, typename K>
  14. using ormap = tree <T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  15. mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
  16.  
  17. const int N = 1e5;
  18.  
  19. char a [3] [N + 1];
  20.  
  21. void solve()
  22. {
  23. int n;
  24. cin >> n;
  25. for (int i = 1; i <= 2; i++)
  26. {
  27. for (int j = 1; j <= n; j++)
  28. cin >> a [i] [j];
  29. }
  30. queue <pair <int, int>> q;
  31. bool visited [3] [n + 1];
  32. for (int i = 1; i < 3; i++)
  33. {
  34. for (int j = 1; j < n + 1; j++)
  35. visited [i] [j] = false;
  36. }
  37. q.push({1, 1});
  38. visited [1] [1] = 1;
  39. while (!q.empty())
  40. {
  41. pair <int, int> fr = q.front();
  42. q.pop();
  43. if (a [3 - fr.first] [fr.second] == '.' && !visited [3 - fr.first] [fr.second])
  44. {
  45. q.push({3 - fr.first, fr.second});
  46. visited [3 - fr.first] [fr.second] = 1;
  47. }
  48. if (fr.second + 1 <= n)
  49. {
  50. if (a [fr.first] [fr.second + 1] == '.' && !visited [fr.first] [fr.second + 1])
  51. {
  52. q.push({fr.first, fr.second + 1});
  53. visited [fr.first] [fr.second + 1] = 1;
  54. }
  55. if (a [3 - fr.first] [fr.second + 1] == '.' && !visited [3 - fr.first] [fr.second + 1])
  56. {
  57. q.push({3 - fr.first, fr.second + 1});
  58. visited [3 - fr.first] [fr.second + 1] = 1;
  59. }
  60. }
  61. }
  62. cout << (visited [2] [n] ? "YES\n" : "NO\n");
  63. }
  64.  
  65. int32_t main(int32_t argc, char* argv[]) {
  66. ios::sync_with_stdio(false);
  67. cin.tie(0);cout.tie(0);
  68. #ifdef FILE
  69. freopen("input.txt", "r", stdin);
  70. freopen("output.txt", "w", stdout);
  71. #endif
  72. int t = 1;
  73. //cin >> t;
  74. while (t--)
  75. solve();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment