-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipes.java
More file actions
33 lines (32 loc) · 858 Bytes
/
Pipes.java
File metadata and controls
33 lines (32 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/** https://codeforces.com/problemset/problem/1234/C #implementation */
import java.util.Scanner;
public class Pipes {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int queries = sc.nextInt();
for (int q = 0; q < queries; q++) {
int n = sc.nextInt();
char[][] arr = new char[2][n];
// input
for (int i = 0; i < 2; i++) {
arr[i] = sc.next().toCharArray();
}
// process
int row = 0;
for (int col = 0; col < n; col++) {
// no need to change row
if (arr[row][col] < '3') {
continue;
}
// need to change row
if (arr[1 - row][col] < '3') {
// can not forward
row = 0;
break;
}
row = 1 - row;
}
System.out.println((row != 1) ? "NO" : "YES");
}
}
}