結果
| 問題 | 
                            No.2094 Symmetry
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  | 
                    
| 提出日時 | 2022-10-08 22:21:28 | 
| 言語 | Lua  (LuaJit 2.1.1734355927)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 713 ms / 2,000 ms | 
| コード長 | 823 bytes | 
| コンパイル時間 | 292 ms | 
| コンパイル使用メモリ | 5,632 KB | 
| 実行使用メモリ | 19,584 KB | 
| 最終ジャッジ日時 | 2024-06-23 00:21:20 | 
| 合計ジャッジ時間 | 17,891 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 34 | 
ソースコード
local n, k = io.read("*n", "*n", "*l")
k = k * 1LL
local hn = n
n = n * 2
local t = {}
local cnt = 0
for i = 1, n do
  local s = io.read()
  t[i] = {}
  for j = 1, n do
    if s:sub(j, j) == "#" then cnt = cnt + 1 end
  end
end
local c = {}
local a = {}
for i = 1, n do
  c[i] = {}
  for j = 1, n do
    c[i][j] = io.read("*n") * 1LL
    table.insert(a, c[i][j])
  end
end
table.sort(a)
local ans1 = 0LL
for i = #a, #a + 1 - cnt, -1 do
  ans1 = ans1 + a[i]
end
-- print(ans1)
if cnt % 2 == 0 then
  a = {}
  for i = 1, n do
    for j = 1, hn do
      table.insert(a, c[i][j] + c[i][n + 1 - j])
    end
  end
  table.sort(a)
  local ans2 = k
  cnt = math.floor(cnt / 2)
  for i = #a, #a + 1 - cnt, -1 do
    ans2 = ans2 + a[i]
  end
  if ans1 < ans2 then ans1 = ans2 end
end
ans1 = tostring(ans1):gsub("LL", "")
print(ans1)