Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int N, K;
- string lwall, rwall;
- bool Visited[2][200005];
- bool check(bool wall, int height)
- {
- if(wall == 0)
- return lwall[height] != 'X';
- else
- {
- return rwall[height] != 'X';
- }
- return false;
- }
- void bfs()
- {
- queue < pair < bool , int > > Q; // SOL = 0 , SAG = 1
- Q.push( make_pair ( 0, 1 ) );
- Visited[0][1] = true;
- bool possible = false;
- bool wall;
- int height;
- while(!Q.empty())
- {
- wall = Q.front().first;
- height = Q.front().second;
- Q.pop();
- cout << wall << " " << height << endl;
- if(height >= N)
- {
- possible = true;
- break;
- }
- if(Visited[wall][height+1] == 0)
- {
- if(check(wall,height+1))
- {
- Q.push( make_pair (wall, height+1) );
- Visited[wall][height+1] = true;
- }
- }
- if(height-1 > 0 && Visited[wall][height-1] == 0)
- {
- if(check(wall,height-1))
- {
- Q.push( make_pair (wall, height-1) );
- Visited[wall][height-1] = true;
- }
- }
- if(Visited[1-wall][height+K] == 0)
- {
- if(check(1-wall,height+K))
- {
- Q.push( make_pair (1-wall, height+K) );
- Visited[1-wall][height+K] = true;
- }
- }
- }
- if(possible)
- cout << "YES" << endl;
- else
- cout << "NO" << endl;
- }
- int main() {
- cin >> N >> K;
- cin >> lwall >> rwall;
- lwall = '.' + lwall;
- rwall = '.' + rwall;
- bfs();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement