結果

問題 No.707 書道
ユーザー 👑 obakyanobakyan
提出日時 2019-04-28 19:19:32
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 18:19:29
合計ジャッジ時間 814 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ior = io.read
local h, w = ior("*n", "*n", "*l")
local xs, ys, cnt = {}, {}, 0
local str =""
for i_h = 1, h do
  str = ior()
  for i_w = 1, w do
    if(str:sub(i_w, i_w) == "1") then
      table.insert(xs, i_w)
      table.insert(ys, i_h)
      cnt = cnt + 1
    end
  end
end
local msq, mmi = math.sqrt, math.min
local function getlen(x, y)
  local len = 0
  for i = 1, cnt do
    len = len + msq((x - xs[i]) * (x - xs[i]) + (y - ys[i]) * (y - ys[i]))
  end
  return len
end
local minlen = getlen(1, 0)
for i_w = 2, w do
  minlen = mmi(minlen, getlen(i_w, 0))
end
for i_w = 1, w do
  minlen = mmi(minlen, getlen(i_w, h + 1))
end
for i_h = 1, h do
  minlen = mmi(minlen, getlen(0, i_h))
end
for i_h = 1, h do
  minlen = mmi(minlen, getlen(w + 1, i_h))
end
print(string.format("%.8f", minlen))
0