結果
問題 | No.1588 Connection |
ユーザー | 👑 obakyan |
提出日時 | 2022-05-08 16:29:00 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 1,905 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 29,760 KB |
平均クエリ数 | 372.81 |
最終ジャッジ日時 | 2024-07-08 04:52:19 |
合計ジャッジ時間 | 3,306 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
25,220 KB |
testcase_01 | AC | 18 ms
25,220 KB |
testcase_02 | AC | 20 ms
24,964 KB |
testcase_03 | AC | 19 ms
24,452 KB |
testcase_04 | AC | 18 ms
24,836 KB |
testcase_05 | AC | 18 ms
24,580 KB |
testcase_06 | AC | 20 ms
25,220 KB |
testcase_07 | AC | 20 ms
25,220 KB |
testcase_08 | AC | 22 ms
24,452 KB |
testcase_09 | AC | 20 ms
25,220 KB |
testcase_10 | AC | 19 ms
25,220 KB |
testcase_11 | AC | 20 ms
24,836 KB |
testcase_12 | AC | 21 ms
25,220 KB |
testcase_13 | AC | 23 ms
25,220 KB |
testcase_14 | AC | 20 ms
25,220 KB |
testcase_15 | AC | 21 ms
24,452 KB |
testcase_16 | AC | 20 ms
24,836 KB |
testcase_17 | AC | 20 ms
24,836 KB |
testcase_18 | AC | 19 ms
25,220 KB |
testcase_19 | AC | 23 ms
25,220 KB |
testcase_20 | AC | 31 ms
29,656 KB |
testcase_21 | AC | 80 ms
29,760 KB |
testcase_22 | AC | 80 ms
29,400 KB |
testcase_23 | AC | 44 ms
25,220 KB |
testcase_24 | AC | 31 ms
24,836 KB |
testcase_25 | AC | 67 ms
29,656 KB |
testcase_26 | AC | 64 ms
29,656 KB |
testcase_27 | AC | 35 ms
24,964 KB |
testcase_28 | AC | 31 ms
25,220 KB |
testcase_29 | AC | 67 ms
25,220 KB |
testcase_30 | AC | 75 ms
25,220 KB |
testcase_31 | AC | 19 ms
24,556 KB |
ソースコード
local mfl, mce = math.floor, math.ceil local function query(str) io.write(str .. "\n") io.flush() local ret = io.read("*l") return ret end local n, m = io.read("*n", "*n", "*l") local t = {} for i = 1, 4 * n * n do t[i] = false end local map = {} -- 0:unknown, 1:black, 2:white for i = 1, n * n do map[i] = 0 end map[1], map[n * n] = 1, 1 local function checkmap(row, col) local mapidx = (row - 1) * n + col if map[mapidx] == 0 then local ans = query(row .. " " .. col) if ans == "Black" then map[mapidx] = 1 else map[mapidx] = 2 end end end local pos = 1 while true do -- print(pos) if t[pos] then io.write("No\n") io.flush() os.exit() end t[pos] = true local way = mce(pos / n / n) local mapidx = pos - (way - 1) * n * n if mapidx == n * n then io.write("Yes\n") io.flush() os.exit() end local row = mce(mapidx / n) local col = mapidx - (row - 1) * n if way == 1 then -- up if 1 < row then checkmap(row - 1, col) end if 1 < row and map[mapidx - n] == 1 then pos = 3 * n * n + (row - 2) * n + col else pos = 1 * n * n + (row - 1) * n + col end elseif way == 2 then -- right if col < n then checkmap(row, col + 1) end if col < n and map[mapidx + 1] == 1 then pos = 0 * n * n + (row - 1) * n + col + 1 else pos = 2 * n * n + (row - 1) * n + col end elseif way == 3 then -- down if row < n then checkmap(row + 1, col) end if row < n and map[mapidx + n] == 1 then pos = 1 * n * n + row * n + col else pos = 3 * n * n + (row - 1) * n + col end else -- left if 1 < col then checkmap(row, col - 1) end if 1 < col and map[mapidx - 1] == 1 then pos = 2 * n * n + (row - 1) * n + col - 1 else pos = 0 * n * n + (row - 1) * n + col end end end