40 lines
730 B
Java
40 lines
730 B
Java
package chelper;
|
|
|
|
import io.InputReader;
|
|
import io.OutputWriter;
|
|
|
|
public class Hanoi {
|
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
|
int n = in.nextInt();
|
|
int[] a = new int[n];
|
|
|
|
String s = in.nextString();
|
|
for (int i = 0; i < n; i++) {
|
|
a[i] = s.charAt(i) - 'A';
|
|
}
|
|
|
|
for (int i = n - 1; i >= 0; i--) {
|
|
if (a[i] == 2) {
|
|
out.println("NO");
|
|
return;
|
|
}
|
|
|
|
if (a[i] == 1) {
|
|
for (int j = 0; j < n; j++) {
|
|
if (a[j] < 2) {
|
|
a[j] = (1 + a[j]) % 2;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < n; j++) {
|
|
if (a[j] > 1) {
|
|
a[j] = 1 + a[j] % 2;
|
|
}
|
|
}
|
|
}
|
|
|
|
out.println("YES");
|
|
}
|
|
}
|