結果
問題 | No.5006 Hidden Maze |
ユーザー | Yu_212 |
提出日時 | 2022-06-12 16:54:01 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 31,166 bytes |
コンパイル時間 | 2,909 ms |
実行使用メモリ | 78,340 KB |
スコア | 74,331 |
平均クエリ数 | 247.58 |
最終ジャッジ日時 | 2022-06-12 16:54:36 |
合計ジャッジ時間 | 34,630 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 154 ms
55,572 KB |
testcase_01 | AC | 222 ms
58,660 KB |
testcase_02 | AC | 176 ms
56,516 KB |
testcase_03 | AC | 115 ms
52,672 KB |
testcase_04 | AC | 166 ms
55,700 KB |
testcase_05 | RE | - |
testcase_06 | AC | 236 ms
59,964 KB |
testcase_07 | RE | - |
testcase_08 | AC | 153 ms
55,864 KB |
testcase_09 | AC | 169 ms
55,888 KB |
testcase_10 | AC | 156 ms
56,396 KB |
testcase_11 | AC | 119 ms
53,088 KB |
testcase_12 | AC | 143 ms
54,364 KB |
testcase_13 | AC | 188 ms
56,740 KB |
testcase_14 | AC | 154 ms
56,604 KB |
testcase_15 | AC | 153 ms
55,884 KB |
testcase_16 | AC | 149 ms
54,732 KB |
testcase_17 | AC | 163 ms
56,084 KB |
testcase_18 | AC | 252 ms
59,824 KB |
testcase_19 | AC | 93 ms
51,372 KB |
testcase_20 | AC | 140 ms
53,528 KB |
testcase_21 | RE | - |
testcase_22 | AC | 162 ms
55,660 KB |
testcase_23 | AC | 209 ms
57,164 KB |
testcase_24 | AC | 250 ms
59,800 KB |
testcase_25 | AC | 139 ms
54,280 KB |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | AC | 103 ms
51,212 KB |
testcase_29 | RE | - |
testcase_30 | AC | 131 ms
53,116 KB |
testcase_31 | AC | 133 ms
53,276 KB |
testcase_32 | AC | 179 ms
55,996 KB |
testcase_33 | AC | 149 ms
54,952 KB |
testcase_34 | AC | 161 ms
56,492 KB |
testcase_35 | AC | 157 ms
56,072 KB |
testcase_36 | AC | 163 ms
55,868 KB |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | AC | 139 ms
53,520 KB |
testcase_40 | AC | 155 ms
55,956 KB |
testcase_41 | AC | 157 ms
55,704 KB |
testcase_42 | AC | 165 ms
56,296 KB |
testcase_43 | AC | 161 ms
55,984 KB |
testcase_44 | AC | 108 ms
53,056 KB |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | AC | 163 ms
56,372 KB |
testcase_48 | AC | 142 ms
54,432 KB |
testcase_49 | RE | - |
testcase_50 | AC | 140 ms
53,824 KB |
testcase_51 | AC | 142 ms
54,680 KB |
testcase_52 | AC | 175 ms
56,520 KB |
testcase_53 | AC | 285 ms
60,396 KB |
testcase_54 | AC | 148 ms
56,052 KB |
testcase_55 | AC | 167 ms
56,528 KB |
testcase_56 | AC | 158 ms
55,748 KB |
testcase_57 | RE | - |
testcase_58 | AC | 169 ms
56,600 KB |
testcase_59 | AC | 152 ms
55,620 KB |
testcase_60 | AC | 142 ms
52,988 KB |
testcase_61 | AC | 147 ms
56,488 KB |
testcase_62 | AC | 190 ms
57,256 KB |
testcase_63 | AC | 160 ms
56,492 KB |
testcase_64 | AC | 399 ms
61,336 KB |
testcase_65 | AC | 155 ms
56,156 KB |
testcase_66 | AC | 130 ms
53,540 KB |
testcase_67 | AC | 185 ms
55,664 KB |
testcase_68 | RE | - |
testcase_69 | AC | 171 ms
56,396 KB |
testcase_70 | AC | 98 ms
51,728 KB |
testcase_71 | AC | 114 ms
52,404 KB |
testcase_72 | AC | 142 ms
54,572 KB |
testcase_73 | AC | 392 ms
62,452 KB |
testcase_74 | RE | - |
testcase_75 | AC | 168 ms
56,808 KB |
testcase_76 | AC | 187 ms
56,892 KB |
testcase_77 | RE | - |
testcase_78 | AC | 146 ms
54,140 KB |
testcase_79 | RE | - |
testcase_80 | AC | 136 ms
53,200 KB |
testcase_81 | AC | 164 ms
56,548 KB |
testcase_82 | AC | 135 ms
54,532 KB |
testcase_83 | AC | 118 ms
52,944 KB |
testcase_84 | AC | 155 ms
56,312 KB |
testcase_85 | AC | 201 ms
58,556 KB |
testcase_86 | AC | 109 ms
52,800 KB |
testcase_87 | AC | 212 ms
58,872 KB |
testcase_88 | RE | - |
testcase_89 | RE | - |
testcase_90 | AC | 157 ms
56,072 KB |
testcase_91 | AC | 142 ms
55,124 KB |
testcase_92 | AC | 238 ms
59,260 KB |
testcase_93 | AC | 154 ms
54,712 KB |
testcase_94 | RE | - |
testcase_95 | AC | 167 ms
56,048 KB |
testcase_96 | AC | 151 ms
55,744 KB |
testcase_97 | AC | 163 ms
55,976 KB |
testcase_98 | RE | - |
testcase_99 | RE | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.function.IntUnaryOperator; import java.util.function.LongUnaryOperator; import java.util.stream.Collectors; public class Main { static In in = new In(); static Out out = new Out(false); static final long inf = 0x1fffffffffffffffL; static final int iinf = 0x3fffffff; static final double eps = 1e-9; static long mod = 998244353; boolean isLocal = false; double p; int n = 20; Pos[] instances = new Pos[n * n]; Pos[][] moved = new Pos[4][n * n]; String[] roads = new String[n * n]; double[][] walls = new double[4][n * n]; void solve() { for (int i = 0; i < n * n; i++) { instances[i] = new Pos(i % n, i / n, i); } for (int d = 0; d < 4; d++) { for (int i = 0; i < n * n; i++) { int nx = i % n + (d - 1) % 2; int ny = i / n + (d - 2) % 2; if (0 <= nx && nx < n && 0 <= ny && ny < n) { moved[d][i] = instances[ny * n + nx]; } } } in.nextInt(); in.nextInt(); p = in.nextInt() / 100.0; w = isLocal ? gen() : null; roads[0] = ""; for (int i = 0; i < 4; i++) { for (int j = 0; j < n * n; j++) { if (pos(j).moved(i) == null) { walls[i][j] = 1; } else { walls[i][j] = 0.5; } } } if (isLocal) { debug(w); } for (int t = 0; t < 1000; t++) { // BitBoard visited = BitBoard.zeros(n); // visited.set(0, 0); String ask = bfs(t); // StringBuilder ask = dfs(pos(0, 0), 0, visited).reverse(); int ret = ask(ask.toString()); if (ret == -1) { return; } } if (isLocal) { debug(w); } throw new RuntimeException(); } boolean[][] gen() { boolean[][] w = new boolean[4][n * n]; int c = 0; ThreadLocalRandom rand = ThreadLocalRandom.current(); int m = rand.nextInt(100, 200); for (int i = 0; i < m; i++) { if (rand.nextInt(2) == 0) { int ii = rand.nextInt(0, 20); int jj = rand.nextInt(0, 19); w[2][ii * n + jj] = true; w[0][ii * n + jj + 1] = true; if (reachable(w) < n * n) { w[2][ii * n + jj] = false; w[0][ii * n + jj + 1] = false; } c++; } else { int ii = rand.nextInt(0, 19); int jj = rand.nextInt(0, 20); w[3][ii * n + jj] = true; w[1][(ii + 1) * n + jj] = true; if (reachable(w) < n * n) { w[3][ii * n + jj] = false; w[1][(ii + 1) * n + jj] = false; } c++; } } return w; } int reachable(boolean[][] w) { BitBoard bb = BitBoard.zeros(n); Deque<Pos> deque = new ArrayDeque<>(); deque.addLast(pos(0)); bb.set(0, 0); while (!deque.isEmpty()) { Pos v = deque.remove(); for (int dir = 0; dir < 4; dir++) { Pos nei = v.moved(dir); if (nei == null || w[dir][v.z] || bb.get(nei.x, nei.y)) { continue; } bb.set(nei.x, nei.y); deque.addLast(nei); } } return bb.countOne(); } int virtual(boolean[][] w, String moves) { Pos cur = pos(0, 0); for (int i = 0; i < moves.length(); i++) { int dir = "LURD".indexOf(moves.charAt(i)); if (ThreadLocalRandom.current().nextInt(100) <= p) { return i; } if (cur.moved(dir) == null) { throw new RuntimeException(); } if (w[dir][cur.z]) { return i; } cur = cur.moved(dir); } if (cur == pos(n - 1, n - 1)) { return -1; } return moves.length(); } String bfs(int turn) { class State implements Comparable<State> { final Pos pos; final int dist; final double prob; State(Pos pos, int dist, double prob) { this.pos = pos; this.dist = dist; this.prob = prob; } @Override public int compareTo(State o) { if (dist != o.dist) { return Integer.compare(dist, o.dist); } else if (prob != o.prob) { return -Double.compare(prob, o.prob); } else { return Integer.compare(hashCode(), o.hashCode()); } } @Override public String toString() { return "State{" + "pos=" + pos + ", dist=" + dist + ", prob=" + prob + '}'; } } PriorityQueue<State> queue = new PriorityQueue<>(); int[] prev = new int[n * n]; State[] s = new State[n * n]; for (int i = 0; i < n * n; i++) { s[i] = new State(pos(i), iinf, 0); } Arrays.fill(prev, -1); s[0] = new State(pos(0), 0, 1); queue.add(s[0]); Pos best = null; while (!queue.isEmpty()) { State state = queue.remove(); Pos cur = state.pos; if (s[cur.z].compareTo(state) > 0) { continue; } if (best == null || s[best.z].dist < state.dist || s[best.z].dist == state.dist && s[best.z].prob < state.prob) { best = cur; } for (int dir = 0; dir < 4; dir++) { Pos nei = cur.moved(dir); if (nei == null) { continue; } if (walls[dir][cur.z] >= 0.9) { continue; } double pp = state.prob * (1 - walls[dir][cur.z]); State ss = new State(nei, state.dist + 1, pp); if (s[nei.z].compareTo(ss) > 0) { s[nei.z] = ss; prev[nei.z] = dir; queue.add(ss); } } } if (isLocal) { out.debug(s[n * n - 1]); StringBuilder bb = new StringBuilder(); // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // bb.append(String.format("%1.1f", walls[2][i * n + j])).append("|").append(String.format("%1.1f", walls[3][i * n + j])).append(", "); // } // bb.append('\n'); // } // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // bb.append(s[i * n + j].dist).append(", "); // } // bb.append('\n'); // } // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // bb.append(String.format("%2.3f", s[i * n + j].prob)).append(", "); // } // bb.append('\n'); // } // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // bb.append(prev[i * n + j]).append(", "); // } // bb.append('\n'); // } // out.debug(bb); } if (turn >= 10) { best = pos(n * n - 1); } StringBuilder ret = new StringBuilder(); while (best.z != 0) { ret.append("LURD".charAt(prev[best.z])); best = best.moved((prev[best.z] + 2) % 4); } return ret.reverse().toString(); } // StringBuilder dfs(Pos cur, int depth, BitBoard visited) { // List<Integer> cand = new ArrayList<>(); // for (int dir = 0; dir < 4; dir++) { // Pos nei = cur.moved(dir); // if (nei == null || visited.get(nei.x, nei.y) || walls[dir][cur.z] > 0.9) { // continue; // } // cand.add(dir); // } // if (cand.isEmpty()) { // return new StringBuilder(); // } // cand.sort(Comparator.comparingDouble(i -> walls[i][cur.z])); // int dir = cand.get(0); // Pos nei = cur.moved(dir); // visited.set(nei.x, nei.y); // String ret = bfs(); // visited.clear(nei.x, nei.y); // ret.append("LURD".charAt(dir)); // double prob = (1 - walls[dir][cur.z]) * ret.length(); // return ret; // } void debug(boolean[][] w) { char[][] c = new char[n][n * 2 - 1]; for (int i = 0; i < n; i++) { Arrays.fill(c[i], ' '); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (w[2][i * n + j]) { c[i][j * 2 + 1] = '|'; } if (w[3][i * n + j]) { c[i][j * 2] = '_'; } } } for (int i = 0; i < n; i++) { out.debug(String.valueOf(c[i])); } } boolean[][] w; int ask(String moves) { Pos cur = pos(0, 0); out.println(moves); out.flush(); int k = isLocal ? virtual(w, moves) : in.nextInt(); out.debug(k); if (k == -1) { return -1; } int len = moves.length(); for (int i = 0; i <= k && i < len; i++) { int dir = "LURD".indexOf(moves.charAt(i)); if (i == k) { out.debug(cur, dir, walls[dir][cur.z], walls[dir][cur.z] / (walls[dir][cur.z] + p)); walls[dir][cur.z] = walls[dir][cur.z] / (walls[dir][cur.z] + p); } else { String sub = moves.substring(0, i); if (roads[cur.z] == null || roads[cur.z].length() > sub.length()) { roads[cur.z] = sub; } walls[dir][cur.z] = 0; } cur = cur.moved(dir); } return k; } Pos pos(int x, int y) { return instances[y * n + x]; } Pos pos(int z) { return instances[z]; } class Pos implements Comparable<Pos> { final int x, y, z; private Pos(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } Pos moved(int d) { return moved[d][z]; } int dist(Pos o) { return Math.abs(x - o.x) + Math.abs(y - o.y); } int euclid(Pos o) { return Math.abs(x - o.x) + Math.abs(y - o.y); } Pos[] neighbors() { Pos[] p = new Pos[4]; int i = 0; if ((p[i++] = moved(0)) == null) i--; if ((p[i++] = moved(1)) == null) i--; if ((p[i++] = moved(2)) == null) i--; if ((p[i++] = moved(3)) == null) i--; return Arrays.copyOf(p, i); } @Override public int compareTo(Pos o) { return Integer.compare(z, o.z); } @Override public boolean equals(Object o) { return o instanceof Pos && z == ((Pos)o).z; } @Override public int hashCode() { return z; } @Override public String toString() { return String.format("(%d, %d)", x, y); } } static abstract class BitBoard { private static final long[] MASKS = {0, 0x1L, 0x3L, 0x7L, 0xFL, 0x1FL, 0x3FL, 0x7FL, 0xFFL, 0x1FFL, 0x3FFL, 0x7FFL, 0xFFFL, 0x1FFFL, 0x3FFFL, 0x7FFFL, 0xFFFFL, 0x1FFFFL, 0x3FFFFL, 0x7FFFFL, 0xFFFFFL, 0x1FFFFFL, 0x3FFFFFL, 0x7FFFFFL, 0xFFFFFFL, 0x1FFFFFFL, 0x3FFFFFFL, 0x7FFFFFFL, 0xFFFFFFFL, 0x1FFFFFFFL, 0x3FFFFFFFL, 0x7FFFFFFFL, 0xFFFFFFFFL, 0x1FFFFFFFFL, 0x3FFFFFFFFL, 0x7FFFFFFFFL, 0xFFFFFFFFFL, 0x1FFFFFFFFFL, 0x3FFFFFFFFFL, 0x7FFFFFFFFFL, 0xFFFFFFFFFFL, 0x1FFFFFFFFFFL, 0x3FFFFFFFFFFL, 0x7FFFFFFFFFFL, 0xFFFFFFFFFFFL, 0x1FFFFFFFFFFFL, 0x3FFFFFFFFFFFL, 0x7FFFFFFFFFFFL, 0xFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFL, 0x3FFFFFFFFFFFFL, 0x7FFFFFFFFFFFFL, 0xFFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFFL, 0x3FFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFFFL, 0x3FFFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFL, 0x1FFFFFFFFFFFFFFFL, 0x3FFFFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFFFL, 0xFFFFFFFFFFFFFFFFL}; private static class BitBoard8 extends BitBoard { // [][][][][][][][] x1 private final static long[] ONES = {0, 0x1L, 0x101L, 0x10101L, 0x1010101L, 0x101010101L, 0x10101010101L, 0x1010101010101L, 0x101010101010101L}; private BitBoard8(int size) { super(size, new long[1]); } private BitBoard8(int size, long[] board) { super(size, board); } public BitBoard copy() { return new BitBoard8(size, board); } protected int x(int x, int y) { return y << 3 | x; } protected int y(int x, int y) { return 0; } public long line(int y) { return board[0] >>> (y << 3) & 0xFF; } public int countOne() { return Long.bitCount(board[0]); } public void fillOnes() { board[0] = ONES[size] * MASKS[size]; } public void spread() { board[0] |= spread(board[0], 8, ONES[size]) & MASKS[size * 8]; } private static BitBoard compress(long[] lines) { long board = 0; for (long line : lines) { board = board << 8 | line; } return new BitBoard8(lines.length, new long[] {board}); } } private static class BitBoard16 extends BitBoard { // [ ][ ][ ][ ] x4 private final static long[] ONES = {0x1000100010001L, 0x1L, 0x10001L, 0x100010001L}; private BitBoard16(int size) { super(size, new long[(size + 3) >> 2]); } private BitBoard16(int size, long[] board) { super(size, board); } public BitBoard copy() { return new BitBoard16(size, board); } protected int x(int x, int y) { return (y & 3) << 4 | x; } protected int y(int x, int y) { return y >> 2; } public long line(int y) { return board[y >> 2] >>> ((y & 3) << 4) & 0xFFFF; } public int countOne() { if (board.length == 3) { return Long.bitCount(board[0]) + Long.bitCount(board[1]) + Long.bitCount(board[2]); } else { return Long.bitCount(board[0]) + Long.bitCount(board[1]) + Long.bitCount(board[2]) + Long.bitCount(board[3]); } } public void fillOnes() { board[0] = ONES[0] * MASKS[size]; board[1] = ONES[0] * MASKS[size]; if (board.length == 3) { board[2] = ONES[size & 3] * MASKS[size]; } else { board[2] = ONES[0] * MASKS[size]; board[3] = ONES[size & 3] * MASKS[size]; } } public void spread() { long old0 = board[0]; long old1 = board[1]; long old2 = board[2]; board[0] |= spread(old0, 16, ONES[0]) | old1 << 48; board[1] |= spread(old1, 16, ONES[0]) | old2 << 48 | old0 >>> 48; if (board.length == 3) { board[2] |= spread(old2, 16, ONES[0]) & MASKS[(size - 8) * 16] | old1 >>> 48; } else { long old3 = board[3]; board[2] |= spread(old2, 16, ONES[0]) | old3 << 48 | old1 >>> 48; board[3] |= spread(old3, 16, ONES[0]) & MASKS[(size - 12) * 16] | old2 >>> 48; } } private static BitBoard compress(long[] lines) { long[] board = new long[lines.length >> 2]; for (int i = 0; i < lines.length; i++) { board[i >> 2] = board[i >> 2] << 16 | lines[i]; } return new BitBoard16(lines.length, board); } } private static class BitBoard32 extends BitBoard { // [ ][ ] x16 private BitBoard32(int size) { super(size, new long[(size + 1) >> 1]); } private BitBoard32(int size, long[] board) { super(size, board); } public BitBoard copy() { return new BitBoard32(size, board); } protected int x(int x, int y) { return (y & 1) << 5 | x; } protected int y(int x, int y) { return y >> 1; } public long line(int y) { return board[y >> 1] >>> ((y & 1) << 5) & 0xFFFFFFFFL; } public void fillOnes() { Arrays.fill(board, MASKS[size] << 16 | MASKS[size]); if ((size & 1) == 1) { board[board.length - 1] = MASKS[size]; } } public void spread() { long old = 0; for (int i = 0; i < board.length; i++) { if (i > 0) { board[i - 1] |= board[i] << 32; } long old2 = board[i]; board[i] |= spread(board[i], 32, 0x100000001L) | old >>> 32; old = old2; } if ((size & 1) == 1) { board[board.length - 1] &= 0xFFFFFFFFL; } } private static BitBoard compress(long[] lines) { long[] board = new long[lines.length >> 2]; for (int i = 0; i < lines.length; i++) { board[i >> 2] = board[i >> 2] << 16 | lines[i]; } return new BitBoard32(lines.length, board); } } private static class BitBoard64 extends BitBoard { // [ ] x64 private BitBoard64(int size) { super(size, new long[size]); } private BitBoard64(int size, long[] board) { super(size, board); } public BitBoard copy() { return new BitBoard64(size, board); } protected int x(int x, int y) { return x; } protected int y(int x, int y) { return y; } public long line(int y) { return board[y]; } public void fillOnes() { Arrays.fill(board, MASKS[size]); } public void spread() { long old = 0; for (int i = 0; i < board.length; i++) { if (i > 0) { board[i - 1] |= board[i]; } long old2 = board[i]; board[i] |= old | board[i] >>> 1 | board[i] << 1 & MASKS[size]; old = old2; } } private static BitBoard compress(long[] lines) { return new BitBoard64(lines.length, lines); } } protected final long[] board; protected final byte size; private BitBoard(int size, long[] board) { this.size = (byte)size; this.board = board; } public static BitBoard of(long[] lines) { int size = lines.length; if (size <= 8) { return BitBoard8.compress(lines); } else if (size <= 16) { return BitBoard16.compress(lines); } else if (size <= 32) { return BitBoard32.compress(lines); } else if (size <= 64) { return BitBoard64.compress(lines); } throw new IllegalArgumentException(); } public static BitBoard zeros(int size) { if (0 <= size) { if (size <= 8) { return new BitBoard8(size); } else if (size <= 16) { return new BitBoard16(size); } else if (size <= 32) { return new BitBoard32(size); } else if (size <= 64) { return new BitBoard64(size); } } throw new IllegalArgumentException(); } public static BitBoard ones(int size) { BitBoard board = zeros(size); board.fillOnes(); return board; } protected long spread(long a, int b, long ones) { long shiftLeft = (a & ~ones) >>> 1; long shiftRight = (a & ~(ones << size - 1)) << 1; return shiftLeft | shiftRight | a << b | a >>> b; } protected abstract int x(int x, int y); protected abstract int y(int x, int y); public abstract BitBoard copy(); public abstract long line(int y); public abstract void fillOnes(); public abstract void spread(); public BitBoard subboard(int sx, int sy, int size) { long[] lines = new long[size]; for (int i = 0; i < size; i++) { lines[i] = line(sy + i) >> sx & MASKS[size]; } return BitBoard.of(lines); } public void set(int x, int y) { Objects.checkIndex(x, size); Objects.checkIndex(y, size); board[y(x, y)] |= 1L << x(x, y); } public void set(int x, int y, boolean value) { if (value) { set(x, y); } else { clear(x, y); } } public void flip(int x, int y) { Objects.checkIndex(x, size); Objects.checkIndex(y, size); board[y(x, y)] ^= 1L << x(x, y); } public void clear(int x, int y) { Objects.checkIndex(x, size); Objects.checkIndex(y, size); board[y(x, y)] &= ~(1L << x(x, y)); } public boolean get(int x, int y) { Objects.checkIndex(x, size); Objects.checkIndex(y, size); return (line(y) >>> x & 1) == 1; } public void and(BitBoard o) { for (int i = 0; i < board.length; i++) { board[i] &= o.board[i]; } } public void or(BitBoard o) { for (int i = 0; i < board.length; i++) { board[i] |= o.board[i]; } } public void xor(BitBoard o) { for (int i = 0; i < board.length; i++) { board[i] ^= o.board[i]; } } public void andNot(BitBoard o) { for (int i = 0; i < board.length; i++) { board[i] &= ~o.board[i]; } } public int size() { return size; } public int countOne() { int count = 0; for (long bits : board) { count += Long.bitCount(bits); } return count; } public int countZero() { return size * size - countOne(); } @Override public int hashCode() { long h = 1234; for (int i = 0; i < board.length; i++) { h ^= board[i] * (i + 1); } return (int)(h >> 32 ^ h); } @Override public boolean equals(Object o) { return this == o || o instanceof BitBoard && Arrays.equals(board, ((BitBoard)o).board); } @Override public String toString() { StringBuilder builder = new StringBuilder(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { builder.append(get(j, i) ? 'o' : '.'); } if (i + 1 < size) { builder.append('\n'); } } return builder.toString(); } } public static void main(String... args) { new Main().solve(); out.flush(); } } class In { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000); private StringTokenizer tokenizer; String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (IOException ignored) { } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char[] nextCharArray() { return next().toCharArray(); } String[] nextStringArray(int n) { String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = next(); } return s; } char[][] nextCharGrid(int n, int m) { char[][] a = new char[n][m]; for (int i = 0; i < n; i++) { a[i] = next().toCharArray(); } return a; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[] nextIntArray(int n, IntUnaryOperator op) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsInt(nextInt()); } return a; } int[][] nextIntMatrix(int h, int w) { int[][] a = new int[h][w]; for (int i = 0; i < h; i++) { a[i] = nextIntArray(w); } return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long[] nextLongArray(int n, LongUnaryOperator op) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsLong(nextLong()); } return a; } long[][] nextLongMatrix(int h, int w) { long[][] a = new long[h][w]; for (int i = 0; i < h; i++) { a[i] = nextLongArray(w); } return a; } List<List<Integer>> nextEdges(int n, int m, boolean directed) { List<List<Integer>> res = new ArrayList<>(); for (int i = 0; i < n; i++) { res.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int u = nextInt() - 1; int v = nextInt() - 1; res.get(u).add(v); if (!directed) { res.get(v).add(u); } } return res; } } class Out { private final PrintWriter out = new PrintWriter(System.out); private final PrintWriter err = new PrintWriter(System.err); boolean autoFlush = false; boolean enableDebug; Out(boolean enableDebug) { this.enableDebug = enableDebug; } void println(Object... args) { if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } out.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); if (autoFlush) { out.flush(); } } void debug(Object... args) { if (!enableDebug) { return; } if (args == null || args.getClass() != Object[].class) { args = new Object[] {args}; } err.println(Arrays.stream(args).map(obj -> { Class<?> clazz = obj == null ? null : obj.getClass(); return clazz == Double.class ? String.format("%.10f", obj) : clazz == byte[].class ? Arrays.toString((byte[])obj) : clazz == short[].class ? Arrays.toString((short[])obj) : clazz == int[].class ? Arrays.toString((int[])obj) : clazz == long[].class ? Arrays.toString((long[])obj) : clazz == char[].class ? Arrays.toString((char[])obj) : clazz == float[].class ? Arrays.toString((float[])obj) : clazz == double[].class ? Arrays.toString((double[])obj) : clazz == boolean[].class ? Arrays.toString((boolean[])obj) : obj instanceof Object[] ? Arrays.deepToString((Object[])obj) : String.valueOf(obj); }).collect(Collectors.joining(" "))); err.flush(); } void println(char[] s) { out.println(String.valueOf(s)); if (autoFlush) { out.flush(); } } void println(int[] a) { StringJoiner joiner = new StringJoiner(" "); for (int i : a) { joiner.add(Integer.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void println(long[] a) { StringJoiner joiner = new StringJoiner(" "); for (long i : a) { joiner.add(Long.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void flush() { err.flush(); out.flush(); } }