結果

問題 No.241 出席番号(1)
ユーザー 👑 obakyanobakyan
提出日時 2020-04-23 22:41:00
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 02:59:28
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local n = io.read("*n")
local t = {}
local ans = {}
local ngcnt = {}
local idx = {}
for i = 1, n do
  ans[i] = 1000000007
  idx[i] = i
  ngcnt[i] = 0
  t[i] = {}
  for j = 1, n do
    t[i][j] = true
  end
end
for i = 1, n do
  local a = io.read("*n") + 1
  if a <= n then
    t[i][a] = false
    ngcnt[a] = ngcnt[a] + 1
  end
end
table.sort(idx, function(a, b) return ngcnt[a] < ngcnt[b] end)
if ngcnt[idx[n]] == n then
  print(-1)
  os.exit()
end
local function debug()
  print("---")
  for i = 1, n do
    for j = 1, n do
      io.write(t[i][j] and 1 or 0)
      io.write(j == n and "\n" or " ")
    end
  end
end
for i = 1, n do
  -- debug()
  local num = idx[#idx]
  for iuser = 1, n do
    if t[iuser][num] then
      ans[iuser] = num - 1
      for j = 1, n do
        if t[iuser][j] then
          ngcnt[j] = ngcnt[j] + 1
        end
        t[j][num] = false
        t[iuser][j] = false
      end
      break
    end
  end
  if i ~= n then
    table.remove(idx)
    table.sort(idx, function(a, b) return ngcnt[a] < ngcnt[b] end)
  end
end
print(table.concat(ans, "\n"))
0