import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); sc.nextLine(); String a = sc.nextLine(); String b = sc.nextLine(); String c = sc.nextLine(); int q = sc.nextInt(); sc.nextLine();
char[] t = sc.nextLine().trim().toCharArray();
int[][] cases = new int[q][2];
char[] change = new char[q];
for (int i = 0; i < q; ++i) {
cases[i][0] = sc.nextInt() - 1;
cases[i][1] = sc.nextInt() - 1;
change[i] = sc.next().charAt(0);
}
int inf = (int) Math.pow(10,9);HashSet<String> set = new HashSet<>();
String[][][] dp = new String[18][18][18];
dp[1][0][0] = a;
dp[0][1][0] = b;
dp[0][0][1] = c;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (i == 0 && j ==0 && k == 0) continue;
dp[i + 1][j][k] = cross(dp[i][j][k], a);
dp[i][j + 1][k] = cross(dp[i][j][k], b);
dp[i][j][k + 1] = cross(dp[i][j][k], c);
}
}
}
for (String[][] i : dp) {
for (String j[] : i) {
for (String k : j) {
if (k != null) set.add(k);
}
}
}
dp = new String[18][18][18];
dp[1][0][0] = a;
dp[0][1][0] = b;
dp[0][0][1] = c;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
for (int i = 0; i < 3; i++) {
if (i == 0 && j ==0 && k == 0) continue;
dp[i + 1][j][k] = cross(dp[i][j][k], a);
dp[i][j + 1][k] = cross(dp[i][j][k], b);
dp[i][j][k + 1] = cross(dp[i][j][k], c);
}
}
}
for (String[][] i : dp) {
for (String j[] : i) {
for (String k : j) {
if (k != null) set.add(k);
}
}
}
dp = new String[18][18][18];
dp[1][0][0] = a;
dp[0][1][0] = b;
dp[0][0][1] = c;
for (int k = 0; k < 3; k++) {
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
if (i == 0 && j ==0 && k == 0) continue;
dp[i + 1][j][k] = cross(dp[i][j][k], a);
dp[i][j + 1][k] = cross(dp[i][j][k], b);
dp[i][j][k + 1] = cross(dp[i][j][k], c);
}
}
}
for (String[][] i : dp) {
for (String j[] : i) {
for (String k : j) {
if (k != null) set.add(k);
}
}
}
if (set.contains(String.valueOf(t))) {
System.out.println("Yes");
} else {
System.out.println("No");
}
for (int i = 0; i < cases.length; i++) {
for (int j = cases[i][0]; j <= cases[i][1]; ++j) {
t[j] = change[i];
}
if (set.contains(String.valueOf(t))) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
public static String cross(String one, String two) {
String s = "";
char[] x = {'J', 'O', 'I'};
for (int i = 0; i < one.length(); i++) {
if (one.charAt(i) != two.charAt(i)) {
for (char j : x) {
if (j != one.charAt(i) && j != two.charAt(i)) {
s+= j;
}
}
} else {
s += one.charAt(i);
}
}
return s;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1847 ms |
26600 KB |
Output is correct |
2 |
Correct |
1911 ms |
28780 KB |
Output is correct |
3 |
Correct |
2019 ms |
28556 KB |
Output is correct |
4 |
Correct |
2009 ms |
28400 KB |
Output is correct |
5 |
Correct |
1910 ms |
28288 KB |
Output is correct |
6 |
Correct |
1852 ms |
28208 KB |
Output is correct |
7 |
Correct |
1878 ms |
28524 KB |
Output is correct |
8 |
Correct |
1892 ms |
28612 KB |
Output is correct |
9 |
Correct |
1903 ms |
28744 KB |
Output is correct |
10 |
Correct |
1905 ms |
28440 KB |
Output is correct |
11 |
Correct |
1807 ms |
28588 KB |
Output is correct |
12 |
Correct |
2000 ms |
28644 KB |
Output is correct |
13 |
Correct |
1860 ms |
28608 KB |
Output is correct |
14 |
Correct |
1862 ms |
28676 KB |
Output is correct |
15 |
Correct |
1890 ms |
28568 KB |
Output is correct |
16 |
Correct |
1887 ms |
28552 KB |
Output is correct |
17 |
Correct |
1915 ms |
28608 KB |
Output is correct |
18 |
Correct |
1962 ms |
28600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1847 ms |
26600 KB |
Output is correct |
2 |
Correct |
1911 ms |
28780 KB |
Output is correct |
3 |
Correct |
2019 ms |
28556 KB |
Output is correct |
4 |
Correct |
2009 ms |
28400 KB |
Output is correct |
5 |
Correct |
1910 ms |
28288 KB |
Output is correct |
6 |
Correct |
1852 ms |
28208 KB |
Output is correct |
7 |
Correct |
1878 ms |
28524 KB |
Output is correct |
8 |
Correct |
1892 ms |
28612 KB |
Output is correct |
9 |
Correct |
1903 ms |
28744 KB |
Output is correct |
10 |
Correct |
1905 ms |
28440 KB |
Output is correct |
11 |
Correct |
1807 ms |
28588 KB |
Output is correct |
12 |
Correct |
2000 ms |
28644 KB |
Output is correct |
13 |
Correct |
1860 ms |
28608 KB |
Output is correct |
14 |
Correct |
1862 ms |
28676 KB |
Output is correct |
15 |
Correct |
1890 ms |
28568 KB |
Output is correct |
16 |
Correct |
1887 ms |
28552 KB |
Output is correct |
17 |
Correct |
1915 ms |
28608 KB |
Output is correct |
18 |
Correct |
1962 ms |
28600 KB |
Output is correct |
19 |
Execution timed out |
7041 ms |
32516 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1847 ms |
26600 KB |
Output is correct |
2 |
Correct |
1911 ms |
28780 KB |
Output is correct |
3 |
Correct |
2019 ms |
28556 KB |
Output is correct |
4 |
Correct |
2009 ms |
28400 KB |
Output is correct |
5 |
Correct |
1910 ms |
28288 KB |
Output is correct |
6 |
Correct |
1852 ms |
28208 KB |
Output is correct |
7 |
Correct |
1878 ms |
28524 KB |
Output is correct |
8 |
Correct |
1892 ms |
28612 KB |
Output is correct |
9 |
Correct |
1903 ms |
28744 KB |
Output is correct |
10 |
Correct |
1905 ms |
28440 KB |
Output is correct |
11 |
Correct |
1807 ms |
28588 KB |
Output is correct |
12 |
Correct |
2000 ms |
28644 KB |
Output is correct |
13 |
Correct |
1860 ms |
28608 KB |
Output is correct |
14 |
Correct |
1862 ms |
28676 KB |
Output is correct |
15 |
Correct |
1890 ms |
28568 KB |
Output is correct |
16 |
Correct |
1887 ms |
28552 KB |
Output is correct |
17 |
Correct |
1915 ms |
28608 KB |
Output is correct |
18 |
Correct |
1962 ms |
28600 KB |
Output is correct |
19 |
Correct |
1870 ms |
28244 KB |
Output is correct |
20 |
Correct |
1873 ms |
28412 KB |
Output is correct |
21 |
Correct |
1856 ms |
28688 KB |
Output is correct |
22 |
Correct |
1756 ms |
27808 KB |
Output is correct |
23 |
Correct |
1863 ms |
28456 KB |
Output is correct |
24 |
Correct |
1807 ms |
28272 KB |
Output is correct |
25 |
Correct |
1824 ms |
28704 KB |
Output is correct |
26 |
Correct |
1826 ms |
28404 KB |
Output is correct |
27 |
Correct |
1840 ms |
28568 KB |
Output is correct |
28 |
Correct |
1726 ms |
27664 KB |
Output is correct |
29 |
Correct |
1777 ms |
28592 KB |
Output is correct |
30 |
Correct |
1732 ms |
27808 KB |
Output is correct |
31 |
Correct |
1817 ms |
28672 KB |
Output is correct |
32 |
Correct |
1773 ms |
28656 KB |
Output is correct |
33 |
Correct |
1794 ms |
28524 KB |
Output is correct |
34 |
Correct |
1725 ms |
28068 KB |
Output is correct |
35 |
Correct |
1765 ms |
28684 KB |
Output is correct |
36 |
Correct |
1759 ms |
28768 KB |
Output is correct |
37 |
Correct |
1846 ms |
28624 KB |
Output is correct |
38 |
Correct |
1781 ms |
28768 KB |
Output is correct |
39 |
Correct |
1758 ms |
28668 KB |
Output is correct |
40 |
Correct |
1776 ms |
28680 KB |
Output is correct |
41 |
Correct |
1783 ms |
28556 KB |
Output is correct |
42 |
Correct |
1748 ms |
28792 KB |
Output is correct |
43 |
Correct |
1780 ms |
28592 KB |
Output is correct |
44 |
Correct |
1778 ms |
28592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1847 ms |
26600 KB |
Output is correct |
2 |
Correct |
1911 ms |
28780 KB |
Output is correct |
3 |
Correct |
2019 ms |
28556 KB |
Output is correct |
4 |
Correct |
2009 ms |
28400 KB |
Output is correct |
5 |
Correct |
1910 ms |
28288 KB |
Output is correct |
6 |
Correct |
1852 ms |
28208 KB |
Output is correct |
7 |
Correct |
1878 ms |
28524 KB |
Output is correct |
8 |
Correct |
1892 ms |
28612 KB |
Output is correct |
9 |
Correct |
1903 ms |
28744 KB |
Output is correct |
10 |
Correct |
1905 ms |
28440 KB |
Output is correct |
11 |
Correct |
1807 ms |
28588 KB |
Output is correct |
12 |
Correct |
2000 ms |
28644 KB |
Output is correct |
13 |
Correct |
1860 ms |
28608 KB |
Output is correct |
14 |
Correct |
1862 ms |
28676 KB |
Output is correct |
15 |
Correct |
1890 ms |
28568 KB |
Output is correct |
16 |
Correct |
1887 ms |
28552 KB |
Output is correct |
17 |
Correct |
1915 ms |
28608 KB |
Output is correct |
18 |
Correct |
1962 ms |
28600 KB |
Output is correct |
19 |
Execution timed out |
7041 ms |
32516 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |