結果
問題 | No.2476 Knight Game |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-11-05 01:35:27 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,567 bytes |
コンパイル時間 | 849 ms |
コンパイル使用メモリ | 119,116 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-25 22:22:09 |
合計ジャッジ時間 | 3,039 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } // !!!Assume bipartite (n vertices overall)!!! class BMatch { int n; int[][] g; int[] to; bool[] vis; this(int n) { this.n = n; g = new int[][n]; to = new int[n]; vis = new bool[n]; } void ae(int u, int v) { g[u] ~= v; g[v] ~= u; } bool augment(int u) { foreach (v; g[u]) if (!vis[v]) { vis[v] = true; if (to[v] == -1 || augment(to[v])) { to[u] = v; to[v] = u; return true; } } return false; } int solve() { int ret; to[] = -1; foreach (u; 0 .. n) if (to[u] == -1) { vis[] = false; if (augment(u)) ++ret; } return ret; } } enum LIM = 7; bool[][][][] ANS; bool solve(long m, long n, long x, long y) { if (m > n) { swap(m, n); swap(x, y); } if (m < LIM && n < LIM) { return ANS[m][n][x][y]; } else if (m == 1) { return false; } else if (m == 2) { if (n % 2 != 0) { return true; } else { return (y % 4 != 0); } } else { if (m % 2 != 0 && n % 2 != 0) { return ((x + y) % 2 != 0); } else { return true; } } } void main() { ANS = new bool[][][][](LIM, LIM); foreach (m; 1 .. LIM) foreach (n; m .. LIM) { int calc(int x0, int y0) { auto bm = new BMatch(m * n); foreach (x; 0 .. m) foreach (y; 0 .. n) if (!(x0 == x && y0 == y)) { foreach (dx; -2 .. +2 + 1) foreach (dy; -2 .. +2 + 1) if (dx^^2 + dy^^2 == 5) { const xx = x + dx; const yy = y + dy; if (0 <= xx && xx < m && 0 <= yy && yy < n && !(x0 == xx && y0 == yy)) { bm.ae(x * n + y, xx * n + yy); } } } const res = bm.solve; return res; } ANS[m][n] = new bool[][](m, n); const ma = calc(-1, -1); foreach (x; 0 .. m) foreach (y; 0 .. n) { const ma1 = calc(x, y); ANS[m][n][x][y] = (ma > ma1); } debug { writeln(m, " ", n); foreach (x; 0 .. m) { foreach (y; 0 .. n) write(ANS[m][n][x][y] ? 1 : 0); writeln; } } } try { for (; ; ) { const numCases = readInt; foreach (caseId; 0 .. numCases) { const M = readLong; const N = readLong; const X = readLong - 1; const Y = readLong - 1; const ans = solve(M, N, X, Y); writeln(ans ? "Alice" : "Bob"); } } } catch (EOFException e) { } }