結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー 👑 obakyanobakyan
提出日時 2022-08-17 00:10:23
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 21 ms / 3,153 ms
コード長 2,854 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 17:51:07
合計ジャッジ時間 26,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local w, h, x = io.read("*n", "*n", "*n")
if x == 0 then
  for i = 1, h do
    print(string.rep("0", w))
  end
  os.exit()
end
if w == 1 then
  if h == 1 then
    if 9 < x then
      print(-1)
    else
      print(x)
    end
  elseif h % 3 ~= 2 or 18 < x then
    print(-1)
  else
    local t = {}
    t[1] = math.min(x, 9)
    t[2] = x - t[1]
    for i = 1, h do
      if i % 3 == 1 then
        print(t[1])
      elseif i % 3 == 2 then
        print(t[2])
      else
        print(0)
      end
    end
  end
  os.exit()
end
if h == 1 then
  if w % 3 ~= 2 or 18 < x then
    print(-1)
  else
    local t = {}
    t[1] = math.min(x, 9)
    t[2] = x - t[1]
    for j = 1, w do
      if j % 3 == 1 then
        io.write(t[1])
      elseif j % 3 == 2 then
        io.write(t[2])
      else
        io.write(0)
      end
    end
    io.write("\n")
  end
  os.exit()
end
if 36 < x then
  print(-1)
  os.exit()
end
local rx = x
local t = {}
for i = 1, 4 do
  t[i] = math.min(x, 9)
  x = x - t[i]
end
x = rx
if 18 < x then
  if w % 3 ~= 2 or h % 3 ~= 2 then
    print(-1)
    os.exit()
  end
  for i = 1, h do
    for j = 1, w do
      if i % 3 == 1 and j % 3 == 1 then
        io.write(t[1])
      elseif i % 3 == 1 and j % 3 == 2 then
        io.write(t[2])
      elseif i % 3 == 2 and j % 3 == 1 then
        io.write(t[3])
      elseif i % 3 == 2 and j % 3 == 2 then
        io.write(t[4])
      else
        io.write(0)
      end
    end
    io.write("\n")
  end
  os.exit()
end
if 9 < x then
  if w % 3 ~= 2 and h % 3 ~= 2 then
    print(-1)
    os.exit()
  end
  if w % 3 == 2 then
    if h % 3 == 0 then
      t[1], t[3] = t[3], t[1]
      t[2], t[4] = t[4], t[2]
    end
  else
    if w % 3 == 0 then
      t[1], t[4] = t[4], t[1]
    else
      t[2], t[3] = t[3], t[2]
    end
  end
  for i = 1, h do
    for j = 1, w do
      if i % 3 == 1 and j % 3 == 1 then
        io.write(t[1])
      elseif i % 3 == 1 and j % 3 == 2 then
        io.write(t[2])
      elseif i % 3 == 2 and j % 3 == 1 then
        io.write(t[3])
      elseif i % 3 == 2 and j % 3 == 2 then
        io.write(t[4])
      else
        io.write(0)
      end
    end
    io.write("\n")
  end
  os.exit()
end
do
  if w % 3 == 0 then
    if h % 3 == 0 then
      t[1], t[4] = t[4], t[1]
    else
      t[1], t[2] = t[2], t[1]
    end
  elseif w % 3 == 1 then
    if h % 3 == 0 then
      t[1], t[3] = t[3], t[1]
    end
  else
    if h % 3 == 0 then
      t[1], t[3] = t[3], t[1]
    end
  end
  for i = 1, h do
    for j = 1, w do
      if i % 3 == 1 and j % 3 == 1 then
        io.write(t[1])
      elseif i % 3 == 1 and j % 3 == 2 then
        io.write(t[2])
      elseif i % 3 == 2 and j % 3 == 1 then
        io.write(t[3])
      elseif i % 3 == 2 and j % 3 == 2 then
        io.write(t[4])
      else
        io.write(0)
      end
    end
    io.write("\n")
  end
  os.exit()
end
0