結果

問題 No.690 E869120 and Constructing Array 4
ユーザー 👑 obakyanobakyan
提出日時 2020-03-28 15:52:54
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 756 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 5,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 17:55:13
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local k = io.read("*n")
if k == 0 then print("2 0")
elseif k == 1 then print("2 1\n1 2")
elseif k == 2 then print("3 3\n1 2\n2 3\n1 3")
else
  local n = 2
  local mul = 1
  while mul < k do
    mul = mul * 2
    n = n + 1
  end
  local ary = {}
  for i = 2, n do
    table.insert(ary, {1, i})
  end
  for i = 3, n - 1 do
    for j = i + 1, n do
      table.insert(ary, {i, j})
    end
  end
  local rem = k - bls(1, n - 3)
  for i = 3, n - 1 do
    local v = bls(1, n - 1 - i)
    if v <= rem then
      table.insert(ary, {2, i})
      rem = rem - v
    end
  end
  if 0 < rem then
    table.insert(ary, {2, n})
  end
  print(n .. " " .. #ary)
  for i = 1, #ary do
    print(ary[i][1] .. " " .. ary[i][2])
  end
end
0