結果

問題 No.1028 闇討ち
ユーザー 👑 obakyanobakyan
提出日時 2020-04-17 21:52:12
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-14 13:31:23
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 71 ms
6,940 KB
testcase_12 AC 329 ms
18,944 KB
testcase_13 AC 325 ms
18,944 KB
testcase_14 AC 173 ms
14,720 KB
testcase_15 AC 51 ms
6,940 KB
testcase_16 AC 347 ms
19,584 KB
testcase_17 AC 341 ms
19,584 KB
testcase_18 AC 343 ms
19,584 KB
testcase_19 AC 343 ms
19,584 KB
testcase_20 AC 344 ms
19,584 KB
testcase_21 AC 341 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n = io.read("*n")

local imosvel = {}
local imos = {}
local base = {}
for i = 1, n do
  imosvel[i] = {}
  imos[i] = {}
  base[i] = 0
  for j = 1, n do
    imosvel[i][j] = 0
    imos[i][j] = 0
  end
end

for ih = 1, n do
  for jw = 0, n - 1 do
    local a = io.read("*n")
    base[a] = base[a] + jw
    --cost zero space: [ih - jw, ih + jw]
    if ih + jw < n then
      imosvel[a][ih + jw + 1] = imosvel[a][ih + jw + 1] + 1
    end
    if 1 < ih - jw then
      imos[a][1] = imos[a][1] + ih - jw
      imosvel[a][1] = imosvel[a][1] - 1
      if ih - jw + 1 <= n then
        imosvel[a][ih - jw + 1] = imosvel[a][ih - jw + 1] + 1
      end
    end
  end
end
local tot = 0
for i = 1, n do
  imos[i][1] = imos[i][1] + imosvel[i][1]
  local cand = imos[i][1]
  for j = 2, n do
    imosvel[i][j] = imosvel[i][j] + imosvel[i][j - 1]
    imos[i][j] = imos[i][j] + imos[i][j - 1] + imosvel[i][j]
    cand = mmi(cand, imos[i][j])
  end
  tot = tot + base[i] + cand
end
print(tot)
0