結果
問題 | No.506 限られたジャパリまん |
ユーザー | 👑 obakyan |
提出日時 | 2021-07-20 21:46:29 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 2,506 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 6,812 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 04:26:47 |
合計ジャッジ時間 | 1,195 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 5 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 80 ms
5,376 KB |
testcase_09 | AC | 30 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 73 ms
5,376 KB |
testcase_12 | AC | 46 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 59 ms
5,376 KB |
testcase_17 | AC | 5 ms
5,376 KB |
testcase_18 | AC | 6 ms
5,376 KB |
testcase_19 | AC | 11 ms
5,376 KB |
testcase_20 | AC | 21 ms
5,376 KB |
testcase_21 | AC | 8 ms
5,376 KB |
testcase_22 | AC | 25 ms
5,376 KB |
testcase_23 | AC | 17 ms
5,376 KB |
testcase_24 | AC | 5 ms
5,376 KB |
ソースコード
local bls, brs = bit.lshift, bit.rshift local bxor = bit.bxor local function badd(a, b) return (a + b) % mod end local w, h, k, p = io.read("*n", "*n", "*n", "*n", "*l") h, w = h + 1, w + 1 local row, col, name = {}, {}, {} for i = 1, k do local a, b, c = io.read():match("(%d+) (%d+) (%w+)") col[i] = tonumber(a) + 1 row[i] = tonumber(b) + 1 name[i] = c end local map = {} for i = 1, h do map[i] = {} for j = 1, w do map[i][j] = true end end for i = 1, k do map[row[i]][col[i]] = false end local function grayCode(x) return bxor(x, brs(x, 1)) end local function grayWalk(size, add_func, rm_func, work_func) local prv = 0 local total = bls(1, size) - 1 local bpos = {} for i = 1, size do bpos[bls(1, i - 1)] = i end work_func() for i = 1, total do local v = grayCode(i) if prv < v then prv, v = v, v - prv add_func(bpos[v]) else prv, v = v, prv - v rm_func(bpos[v]) end work_func() end end local box = 0 local bcnt = 0 local t = {} for i = 1, h do t[i] = {} end local retmax, retbox = 0LL, 0 local function add_func(idx) map[row[idx]][col[idx]] = true bcnt = bcnt + 1 box = box + bls(1, idx - 1) end local function rm_func(idx) map[row[idx]][col[idx]] = false bcnt = bcnt - 1 box = box - bls(1, idx - 1) end local function work_func() if bcnt == p then t[1][1] = 1LL for j = 2, w do if map[1][j] then if t[1][j - 1] < 0LL then t[1][j] = -1LL else t[1][j] = 1LL end else t[1][j] = -1LL end end for i = 2, h do if map[i][1] then t[i][1] = t[i - 1][1] else t[i][1] = -1LL end for j = 2, w do if map[i][j] then if t[i][j - 1] < 0LL and t[i - 1][j] < 0LL then t[i][j] = -1LL elseif t[i][j - 1] < 0LL then t[i][j] = t[i - 1][j] elseif t[i - 1][j] < 0LL then t[i][j] = t[i][j - 1] else t[i][j] = t[i - 1][j] + t[i][j - 1] end else t[i][j] = -1LL end end end if retmax < t[h][w] then retmax, retbox = t[h][w], box end end end grayWalk(k, add_func, rm_func, work_func) if retmax == 0LL then print(0) else retmax = tostring(retmax % 1000000007LL):gsub("LL", "") print(retmax) local i = 0 while 0 < retbox do i = i + 1 if retbox % 2 == 1 then print(name[i]) end retbox = brs(retbox, 1) end end