結果
問題 | No.1588 Connection |
ユーザー | 👑 obakyan |
提出日時 | 2022-05-08 16:29:00 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 1,905 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 5,212 KB |
実行使用メモリ | 28,796 KB |
平均クエリ数 | 372.81 |
最終ジャッジ日時 | 2023-09-22 13:08:17 |
合計ジャッジ時間 | 4,447 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
24,348 KB |
testcase_01 | AC | 26 ms
23,364 KB |
testcase_02 | AC | 25 ms
23,412 KB |
testcase_03 | AC | 25 ms
23,520 KB |
testcase_04 | AC | 25 ms
24,300 KB |
testcase_05 | AC | 26 ms
24,000 KB |
testcase_06 | AC | 27 ms
24,276 KB |
testcase_07 | AC | 26 ms
24,024 KB |
testcase_08 | AC | 28 ms
24,372 KB |
testcase_09 | AC | 26 ms
23,376 KB |
testcase_10 | AC | 26 ms
23,628 KB |
testcase_11 | AC | 27 ms
24,000 KB |
testcase_12 | AC | 29 ms
23,508 KB |
testcase_13 | AC | 31 ms
23,616 KB |
testcase_14 | AC | 26 ms
24,276 KB |
testcase_15 | AC | 26 ms
23,856 KB |
testcase_16 | AC | 26 ms
23,652 KB |
testcase_17 | AC | 26 ms
23,544 KB |
testcase_18 | AC | 26 ms
23,388 KB |
testcase_19 | AC | 28 ms
23,676 KB |
testcase_20 | AC | 35 ms
28,576 KB |
testcase_21 | AC | 93 ms
28,520 KB |
testcase_22 | AC | 95 ms
28,796 KB |
testcase_23 | AC | 52 ms
23,628 KB |
testcase_24 | AC | 40 ms
23,988 KB |
testcase_25 | AC | 78 ms
28,512 KB |
testcase_26 | AC | 76 ms
28,580 KB |
testcase_27 | AC | 45 ms
23,412 KB |
testcase_28 | AC | 40 ms
23,400 KB |
testcase_29 | AC | 84 ms
23,364 KB |
testcase_30 | AC | 93 ms
23,676 KB |
testcase_31 | AC | 25 ms
23,652 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