結果

問題 No.241 出席番号(1)
ユーザー 👑 obakyanobakyan
提出日時 2020-04-23 22:40:09
言語 Lua
(LuaJit 2.1.1696795921)
結果
RE  
実行時間 -
コード長 1,050 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 02:58:09
合計ジャッジ時間 3,152 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 1 ms
5,376 KB
testcase_17 RE -
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 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 RE -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 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
  t[i][a] = false
  ngcnt[a] = ngcnt[a] + 1
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