156 words
1 minutes
[BOJ] 재미있는 파이프 퍼즐
TimeLimit | MemoryLimit | Condition | TAG |
---|---|---|---|
2s | 2048MB | (2 ≤ N ≤ 200000) | GraphTraversal |
그냥 탐색을 돌리며 되는 문제였어서 그냥 풀었던 것 같아요
정답 코드
#include <iostream>
#include <queue>
#include <algorithm>
#include<set>
using namespace std;
int inf = 1e9;
int n;
char board[200'001][2];
bool visited[200'001][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++) cin >> board[i][0];
for(int i = 0; i < n; i++) cin >> board[i][1];
queue<pair<bool, int>> q;
q.push({0, 0});
if(board[0][1] == 'L') q.push({1, 0});
while(!q.empty() && !visited[n-1][1]){
auto [y, x] = q.front(); q.pop();
int nx = x+1;
bool ny = y;
if(board[nx][y] =='L'){
ny = !y;
if(board[nx][ny] == 'I') continue;
}
if(0 <= nx && nx < n){
visited[nx][ny] = true;
q.push({ny, nx});
}
}
if(visited[n-1][1]) cout << "YES";
else cout << "NO";
return 0;
}
[BOJ] 재미있는 파이프 퍼즐
https://compy07.github.io/Blog/posts/boj/32964/