結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 obakyanobakyan
提出日時 2021-07-22 10:45:12
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 5,292 KB
実行使用メモリ 6,476 KB
最終ジャッジ日時 2023-09-24 13:49:35
合計ジャッジ時間 2,885 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 54 ms
4,376 KB
testcase_03 AC 12 ms
4,380 KB
testcase_04 AC 22 ms
4,376 KB
testcase_05 AC 49 ms
6,228 KB
testcase_06 AC 50 ms
6,276 KB
testcase_07 AC 47 ms
6,408 KB
testcase_08 AC 48 ms
6,456 KB
testcase_09 AC 59 ms
6,296 KB
testcase_10 AC 54 ms
6,436 KB
testcase_11 AC 54 ms
6,408 KB
testcase_12 AC 54 ms
6,352 KB
testcase_13 AC 55 ms
6,324 KB
testcase_14 AC 54 ms
6,356 KB
testcase_15 AC 54 ms
6,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local q = io.read("*n")
for iq = 1, q do
  local n = io.read("*n")
  local a = {}
  for i = 1, n do
    a[i] = io.read("*n")
  end
  local t = {}
  local function solve()
    local r1 = 0
    for i = 1, n do
      t[i] = 0
    end
    for i = 1, n do
      if i == n then
        r1 = mma(r1, t[i])
      else
        t[i + 1] = mma(t[i + 1], t[i])
      end
      if i <= n - 2 then
        if a[i] ~= a[i + 2] and 0 < (a[i + 1] - a[i]) * (a[i + 1] - a[i + 2]) then
          if i == n - 2 then
            r1 = mma(r1, t[i] + a[i])
          else
            t[i + 3] = mma(t[i + 3], t[i] + a[i])
          end
        end
      end
    end
    return r1
  end
  local r = solve()
  for irep = 1, 2 do
    local z = a[1]
    for i = 2, n do
      a[i - 1] = a[i]
    end
    a[n] = z
    r = mma(r, solve())
  end
  print(r)
end
0