結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー AEnAEn
提出日時 2022-05-31 17:59:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 3,153 ms
コード長 2,488 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 81,684 KB
最終ジャッジ日時 2023-10-21 00:43:25
合計ジャッジ時間 25,762 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,528 KB
testcase_01 AC 37 ms
53,528 KB
testcase_02 AC 34 ms
53,528 KB
testcase_03 AC 34 ms
53,528 KB
testcase_04 AC 36 ms
53,528 KB
testcase_05 AC 36 ms
53,528 KB
testcase_06 AC 92 ms
81,568 KB
testcase_07 AC 37 ms
55,576 KB
testcase_08 AC 97 ms
81,632 KB
testcase_09 AC 98 ms
81,556 KB
testcase_10 AC 37 ms
55,576 KB
testcase_11 AC 88 ms
81,268 KB
testcase_12 AC 37 ms
55,576 KB
testcase_13 AC 92 ms
81,304 KB
testcase_14 AC 96 ms
81,236 KB
testcase_15 AC 36 ms
55,576 KB
testcase_16 AC 95 ms
81,600 KB
testcase_17 AC 94 ms
81,616 KB
testcase_18 AC 89 ms
81,684 KB
testcase_19 AC 91 ms
81,360 KB
testcase_20 AC 35 ms
55,576 KB
testcase_21 AC 100 ms
81,304 KB
testcase_22 AC 94 ms
81,620 KB
testcase_23 AC 37 ms
55,576 KB
testcase_24 AC 90 ms
81,292 KB
testcase_25 AC 36 ms
55,576 KB
testcase_26 AC 95 ms
81,624 KB
testcase_27 AC 97 ms
81,676 KB
testcase_28 AC 36 ms
55,576 KB
testcase_29 AC 85 ms
81,316 KB
testcase_30 AC 35 ms
55,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

W, H, X = map(int, input().split())
ans = [[0]*(W) for _ in range(H)]

x1 = [1, 1, 0, -1, -1, -1, 0, 1, 0]
y1 = [0, 1, 1, 1, 0, -1, -1, -1, 0]
def debag(X):
    for x in range(H):
        for y in range(W):
            sm = 0
            for px, py in zip(x1, y1):
                cx = x+px; cy = y+py
                if 0<=cx<H and 0<=cy<W:
                    sm += ans[cx][cy]
            if sm != X:
                print(x, y)
                return False
    return True
XX = X
if X > 36:
    print(-1)
elif H==W==1:
    if X > 9:
        print(-1)
    else:
        print(X)
elif W == 1:
    if X > 9*W*2:
        print(-1)
    else:
        res = [min(X, 9), X-min(X, 9), 0]
        for i in range(H):
            print(res[i%3])
elif H == 1:
    if X > 9*H*2:
        print(-1)
    else:
        res = [min(X, 9), X-min(X,9), 0]
        for i in range(W):
            if i < W-1:
                print(res[i%3], end = '')
            else:
                print(res[i%3])
else:
    x = []
    sm, cnt = 0, 0
    for i in range(4):
        x.append(min(9, X-sm))
        cnt += (x[-1]>0)
        sm += x[-1]
    h, w = H%3, W%3
    if h == 0 and w == 0 and cnt == 1:
        for i in range(H):
            for j in range(W):
                if i%3 == 1 and j%3 == 1:
                    ans[i][j] = x[0]
            print(*ans[i], sep='')
    elif ((h==1 and w==0) or (h==1 and w==1) or (h==0 and w==1)) and cnt <= 1:
        for i in range(H):
            for j in range(W):
                if (i+h)%3 == 1 and (j+w)%3 == 1:
                    ans[i][j] = x[0]
            print(*ans[i], sep='')
    elif ((h==2 and w==0) or (h==2 and w==1) or (h==1 and w==2) or (h==0 and w==2)) and cnt <= 2:
        for i in range(H):
            for j in range(W):
                if w == 2:
                    if (i+h)%3 == 1 and j%3 == 0:
                        ans[i][j] = x[0]
                    if (i+h)%3 == 1 and j%3 == 1:
                        ans[i][j] = x[1]
                if h == 2:
                    if i%3 == 0 and (j+w)%3 == 1:
                        ans[i][j] = x[0]
                    if i%3 == 1 and (j+w)%3 == 1:
                        ans[i][j] = x[1]
            print(*ans[i], sep='')
    elif h*w == 4:
        x += [0, 0, 0]
        for i in range(H):
            for j in range(W):
                if i%3 <= 1 and j%3 <= 1:
                    ans[i][j] = x[2*(i%3) + j%3] 
            print(*ans[i], sep='')
    else:
        print(-1)
# print(debag(XX))
0