結果
問題 | No.1028 闇討ち |
ユーザー |
👑 |
提出日時 | 2020-04-17 21:52:12 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 291 ms / 2,000 ms |
コード長 | 1,013 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-10-03 12:07:37 |
合計ジャッジ時間 | 3,763 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
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)