結果

問題 No.94 圏外です。(EASY)
ユーザー 👑 obakyanobakyan
提出日時 2019-04-22 23:51:08
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 09:19:38
合計ジャッジ時間 998 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local x, y = {}, {}
local parent = {}
for i = 1, n do
  x[i], y[i] = io.read("*n", "*n")
  parent[i] = 0
end

local function getroot(idx)
  while(parent[idx] ~= 0) do
    idx = parent[idx]
  end
  return idx
end

local function getsqlen(idx1, idx2)
  return (x[idx1] - x[idx2]) * (x[idx1] - x[idx2]) + (y[idx1] - y[idx2]) * (y[idx1] - y[idx2])
end

for i = 1, n - 1 do
  for j = i + 1, n do
    if(getsqlen(i, j) <= 100) then
      local ip, jp = getroot(i), getroot(j)
      if(ip ~= jp) then parent[jp] = ip end
      if(ip ~= i) then parent[i] = ip end
      if(ip ~= j) then parent[j] = ip end
    end
  end
end

local rootlist = {}
for i = 1, n do
  local r = getroot(i)
  if(rootlist[r] == nil) then rootlist[r] = {} end
  table.insert(rootlist[r], i)
end

local totmaxlen = 0
for key, val in pairs(rootlist) do
  for i = 1, #val - 1 do
    for j = i + 1, #val do
      totmaxlen = math.max(totmaxlen, getsqlen(val[i], val[j]))
    end
  end
end
if(n == 0) then
  print(1)
else
  print(string.format("%.8f", 2 + math.sqrt(totmaxlen)))
end
0