結果

問題 No.360 増加門松列
ユーザー 👑 obakyanobakyan
提出日時 2019-05-26 00:18:28
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 34 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 17:47:26
合計ジャッジ時間 950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,348 KB
testcase_01 AC 8 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 8 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 8 ms
4,348 KB
testcase_20 AC 8 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl = math.floor
local function getpattern(n, patall, idx)
  local used = {}
  local retary = {}
  local div = patall
  for i = 1, n do used[i] = false end
  for i = n, 1, -1 do
    div = mfl(div / i)
    local v_idx = mfl(idx / div)
    idx = idx % div
    local tmp_idx = 0
    for j = 1, n do
      if(not used[j]) then
        if(tmp_idx == v_idx) then
          table.insert(retary, j)
          used[j] = true
          break
        else
          tmp_idx = tmp_idx + 1
        end
      end
    end
  end
  return retary
end

local function isZouKado(x1, x2, x3)
  return x1 < x3 and (x2 - x1) * (x3 - x2) < 0
end

local d = {}
for i = 1, 7 do d[i] = io.read("*n") end
local found = false
for i = 0, 5039 do
  local pat = getpattern(7, 5040, i)
  local t = true
  for j = 1, 5 do
    if not isZouKado(d[pat[j]], d[pat[j + 1]], d[pat[j + 2]]) then
      t = false
      break
    end
  end
  if t then found = true break end
end
print(found and "YES" or "NO")
0