結果
問題 | No.1398 調和の魔法陣 (構築) |
ユーザー |
👑 |
提出日時 | 2022-08-17 00:10:23 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 20 ms / 3,153 ms |
コード長 | 2,854 bytes |
コンパイル時間 | 111 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 18:49:53 |
合計ジャッジ時間 | 23,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
local w, h, x = io.read("*n", "*n", "*n")if x == 0 thenfor i = 1, h doprint(string.rep("0", w))endos.exit()endif w == 1 thenif h == 1 thenif 9 < x thenprint(-1)elseprint(x)endelseif h % 3 ~= 2 or 18 < x thenprint(-1)elselocal t = {}t[1] = math.min(x, 9)t[2] = x - t[1]for i = 1, h doif i % 3 == 1 thenprint(t[1])elseif i % 3 == 2 thenprint(t[2])elseprint(0)endendendos.exit()endif h == 1 thenif w % 3 ~= 2 or 18 < x thenprint(-1)elselocal t = {}t[1] = math.min(x, 9)t[2] = x - t[1]for j = 1, w doif j % 3 == 1 thenio.write(t[1])elseif j % 3 == 2 thenio.write(t[2])elseio.write(0)endendio.write("\n")endos.exit()endif 36 < x thenprint(-1)os.exit()endlocal rx = xlocal t = {}for i = 1, 4 dot[i] = math.min(x, 9)x = x - t[i]endx = rxif 18 < x thenif w % 3 ~= 2 or h % 3 ~= 2 thenprint(-1)os.exit()endfor i = 1, h dofor j = 1, w doif i % 3 == 1 and j % 3 == 1 thenio.write(t[1])elseif i % 3 == 1 and j % 3 == 2 thenio.write(t[2])elseif i % 3 == 2 and j % 3 == 1 thenio.write(t[3])elseif i % 3 == 2 and j % 3 == 2 thenio.write(t[4])elseio.write(0)endendio.write("\n")endos.exit()endif 9 < x thenif w % 3 ~= 2 and h % 3 ~= 2 thenprint(-1)os.exit()endif w % 3 == 2 thenif h % 3 == 0 thent[1], t[3] = t[3], t[1]t[2], t[4] = t[4], t[2]endelseif w % 3 == 0 thent[1], t[4] = t[4], t[1]elset[2], t[3] = t[3], t[2]endendfor i = 1, h dofor j = 1, w doif i % 3 == 1 and j % 3 == 1 thenio.write(t[1])elseif i % 3 == 1 and j % 3 == 2 thenio.write(t[2])elseif i % 3 == 2 and j % 3 == 1 thenio.write(t[3])elseif i % 3 == 2 and j % 3 == 2 thenio.write(t[4])elseio.write(0)endendio.write("\n")endos.exit()enddoif w % 3 == 0 thenif h % 3 == 0 thent[1], t[4] = t[4], t[1]elset[1], t[2] = t[2], t[1]endelseif w % 3 == 1 thenif h % 3 == 0 thent[1], t[3] = t[3], t[1]endelseif h % 3 == 0 thent[1], t[3] = t[3], t[1]endendfor i = 1, h dofor j = 1, w doif i % 3 == 1 and j % 3 == 1 thenio.write(t[1])elseif i % 3 == 1 and j % 3 == 2 thenio.write(t[2])elseif i % 3 == 2 and j % 3 == 1 thenio.write(t[3])elseif i % 3 == 2 and j % 3 == 2 thenio.write(t[4])elseio.write(0)endendio.write("\n")endos.exit()end