結果

問題 No.1373 Directed Operations
ユーザー 👑 obakyanobakyan
提出日時 2021-07-19 22:24:44
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 5,264 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2023-09-24 12:41:42
合計ジャッジ時間 5,003 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 122 ms
15,500 KB
testcase_03 AC 41 ms
9,604 KB
testcase_04 AC 45 ms
9,500 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 91 ms
12,000 KB
testcase_07 AC 4 ms
4,388 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 46 ms
11,556 KB
testcase_10 AC 39 ms
10,448 KB
testcase_11 AC 10 ms
4,536 KB
testcase_12 AC 41 ms
9,488 KB
testcase_13 AC 6 ms
4,384 KB
testcase_14 AC 120 ms
14,416 KB
testcase_15 AC 104 ms
13,340 KB
testcase_16 AC 123 ms
14,664 KB
testcase_17 AC 96 ms
13,352 KB
testcase_18 AC 53 ms
7,584 KB
testcase_19 AC 35 ms
6,536 KB
testcase_20 AC 49 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local t = {}
for i = 1, n - 1 do
  t[i] = {}
end
for i = 1, n - 1 do
  local a = io.read("*n")
  table.insert(t[a], i)
end
for i = 1, n - 1 do
  for j = 1, #t[i] do
    local k = #t[i] + 1 - j
    if j < k then
      t[i][j], t[i][k] = t[i][k], t[i][j]
    else break
    end
  end
end
local ret = {}
for i = 1, n - 1 do
  ret[i] = 0
end
local curlen = 1
for dst = 2, n do
  while curlen < n and #t[curlen] == 0 do
    curlen = curlen + 1
  end
  if (dst - 1) < curlen then
    print("NO") os.exit()
  end
  local q = t[curlen][#t[curlen]]
  table.remove(t[curlen])
  ret[q] = dst - curlen
end
print("YES")
print(table.concat(ret, "\n"))
0