Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- //#define FILE 10
- #define int int64_t
- using namespace std;
- using namespace __gnu_pbds;
- template<typename T>
- using orset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- template<typename T, typename K>
- using ormap = tree <T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
- const int N = 1e5;
- char a [3] [N + 1];
- void solve()
- {
- int n;
- cin >> n;
- for (int i = 1; i <= 2; i++)
- {
- for (int j = 1; j <= n; j++)
- cin >> a [i] [j];
- }
- queue <pair <int, int>> q;
- bool visited [3] [n + 1];
- for (int i = 1; i < 3; i++)
- {
- for (int j = 1; j < n + 1; j++)
- visited [i] [j] = false;
- }
- q.push({1, 1});
- visited [1] [1] = 1;
- while (!q.empty())
- {
- pair <int, int> fr = q.front();
- q.pop();
- if (a [3 - fr.first] [fr.second] == '.' && !visited [3 - fr.first] [fr.second])
- {
- q.push({3 - fr.first, fr.second});
- visited [3 - fr.first] [fr.second] = 1;
- }
- if (fr.second + 1 <= n)
- {
- if (a [fr.first] [fr.second + 1] == '.' && !visited [fr.first] [fr.second + 1])
- {
- q.push({fr.first, fr.second + 1});
- visited [fr.first] [fr.second + 1] = 1;
- }
- if (a [3 - fr.first] [fr.second + 1] == '.' && !visited [3 - fr.first] [fr.second + 1])
- {
- q.push({3 - fr.first, fr.second + 1});
- visited [3 - fr.first] [fr.second + 1] = 1;
- }
- }
- }
- cout << (visited [2] [n] ? "YES\n" : "NO\n");
- }
- int32_t main(int32_t argc, char* argv[]) {
- ios::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- #ifdef FILE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t = 1;
- //cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment