-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathC.java
More file actions
49 lines (45 loc) · 1.6 KB
/
Copy pathC.java
File metadata and controls
49 lines (45 loc) · 1.6 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package atcoder.grand_45;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public final class C {
public static void main(String[] args) {
final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
final int t = Integer.parseInt(in.nextLine());
for (int x = 0; x < t; x++) {
final int n = Integer.parseInt(in.nextLine());
final int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
in.nextLine();
final String s = in.nextLine();
final List<Integer> left = new ArrayList<>();
final List<Integer> right = new ArrayList<>();
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '1') {
left.add(arr[j]);
} else {
right.add(arr[j]);
}
}
final Set<Integer> leftS = new HashSet<>();
final Set<Integer> rightS = new HashSet<>();
dfs(left, leftS, 0, 0);
dfs(right, rightS, 0, 0);
System.out.println(leftS.equals(rightS) ? 0 : 1);
}
}
public static void dfs(List<Integer> nums, Set<Integer> res, int curr, int idx) {
res.add(curr);
for (int i = idx; i < nums.size(); i++) {
curr ^= nums.get(i);
dfs(nums, res, curr, i + 1);
curr ^= nums.get(i);
}
}
}