結果
問題 | No.334 門松ゲーム |
ユーザー | 👑 obakyan |
提出日時 | 2019-05-06 20:38:18 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 2,768 bytes |
コンパイル時間 | 78 ms |
コンパイル使用メモリ | 6,812 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 09:59:21 |
合計ジャッジ時間 | 956 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 5 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 4 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 10 ms
5,376 KB |
testcase_11 | AC | 5 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
ソースコード
local n = io.read("*n") local k = {} local box = {} for i = 1, n do k[i], box[i] = io.read("*n"), false end local function iskado(i1, i2, i3) return (k[i1] ~= k[i3] and (k[i1] - k[i2]) * (k[i2] - k[i3]) < 0) end local function getbox(i1, i2, i3) local t = {i1, i2, i3} local ret = {0, 0, 0} for i = 1, 3 do local tmp = 0 for j = 1, n do if(not box[j]) then tmp = tmp + 1 if(tmp == t[i]) then ret[i] = j break end end end end box[ret[1]], box[ret[2]], box[ret[3]] = true, true, true return unpack(ret) end local function unsetbox(b1, b2, b3) box[b1], box[b2], box[b3] = false, false, false end local wd1, wd2, wd3 = 0, 0, 0 local d_win_found = false for i1_1 = 1, n - 2 do for i1_2 = i1_1 + 1, n - 1 do for i1_3 = i1_2 + 1, n do wd1, wd2, wd3 = i1_1, i1_2, i1_3 local b1_1, b1_2, b1_3 = getbox(i1_1, i1_2, i1_3) if(iskado(b1_1, b1_2, b1_3)) then if(n <= 5) then d_win_found = true else local e_has_win_route = false for i2_1 = 1, n - 5 do for i2_2 = i2_1 + 1, n - 4 do for i2_3 = i2_2 + 1, n - 3 do local b2_1, b2_2, b2_3 = getbox(i2_1, i2_2, i2_3) if(iskado(b2_1, b2_2, b2_3)) then if(n <= 8) then e_has_win_route = true else local d_has_win_route = false for i3_1 = 1, n - 8 do for i3_2 = i3_1 + 1, n - 7 do for i3_3 = i3_2 + 1, n - 6 do local b3_1, b3_2, b3_3 = getbox(i3_1, i3_2, i3_3) if(iskado(b3_1, b3_2, b3_3)) then if(n <= 11) then d_has_win_route = true else local b4_1, b4_2, b4_3 = getbox(1, 2, 3) if(not iskado(b4_1, b4_2, b4_3)) then d_has_win_route = true end unsetbox(b4_1, b4_2, b4_3) end end unsetbox(b3_1, b3_2, b3_3) if(d_has_win_route) then break end end if(d_has_win_route) then break end end if(d_has_win_route) then break end end if(not d_has_win_route) then e_has_win_route = true end end end unsetbox(b2_1, b2_2, b2_3) if(e_has_win_route) then break end end --i2_3 if(e_has_win_route) then break end end --i2_2 if(e_has_win_route) then break end end --i2_1 if(not e_has_win_route) then d_win_found = true end end--if (6 <= n) end unsetbox(b1_1, b1_2, b1_3) if(d_win_found) then break end end --i1_3 if(d_win_found) then break end end --i1_2 if(d_win_found) then break end end --i1_1 if(d_win_found) then print(wd1 - 1 .. " " .. wd2 - 1 .. " " .. wd3 - 1) else print(-1) end