結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-02-19 22:25:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,238 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 81,224 KB
最終ジャッジ日時 2023-10-15 03:00:27
合計ジャッジ時間 37,917 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,172 KB
testcase_01 AC 70 ms
70,968 KB
testcase_02 AC 78 ms
75,980 KB
testcase_03 AC 70 ms
71,208 KB
testcase_04 AC 73 ms
71,392 KB
testcase_05 AC 71 ms
71,456 KB
testcase_06 WA -
testcase_07 AC 531 ms
80,648 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 537 ms
80,412 KB
testcase_11 WA -
testcase_12 AC 530 ms
80,912 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,019 ms
80,952 KB
testcase_16 AC 247 ms
80,192 KB
testcase_17 AC 581 ms
80,616 KB
testcase_18 AC 392 ms
80,612 KB
testcase_19 AC 589 ms
80,736 KB
testcase_20 AC 486 ms
79,992 KB
testcase_21 AC 245 ms
80,056 KB
testcase_22 AC 586 ms
80,572 KB
testcase_23 AC 1,015 ms
81,068 KB
testcase_24 WA -
testcase_25 AC 502 ms
80,720 KB
testcase_26 AC 243 ms
80,264 KB
testcase_27 WA -
testcase_28 AC 511 ms
80,552 KB
testcase_29 AC 244 ms
80,212 KB
testcase_30 AC 501 ms
80,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def sol(ans):
    for i in range(H):
        for j in range(W):

            now = 0
            for x in range(i-1,i+2):
                for y in range(j-1,j+2):
                    if 0 <= x < H and 0 <= y < W:
                        now += ans[x][y]
            if now != X:
                return False
    for i in ans:
        print ("".join(map(str,i)))
    sys.exit()

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

# type1
for A in range(10):
    for i in range(H):
        for j in range(W):
            if i % 3 == 1:
                ans[i][j] = A
            else:
                ans[i][j] = 0
    sol(ans)

for A in range(10):
    for i in range(H):
        for j in range(W):
            if j % 3 == 1:
                ans[i][j] = A
            else:
                ans[i][j] = 0
    sol(ans)

#type3
for A in range(10):
    for i in range(H):
        for j in range(W):
            if i % 3 == j % 3 == 1:
                ans[i][j] = A
            else:
                ans[i][j] = 0
    sol(ans)

#type2
for A in range(10):
    for B in range(10):
        for i in range(H):
            for j in range(W):
                if i % 3 == 2 or j % 3 == 2:
                    ans[i][j] = 0
                elif i % 3 == j % 3:
                    ans[i][j] = A
                else:
                    ans[i][j] = B
        sol(ans)

#type4
for A in range(10):
    for B in range(10):
        for C in range(10):
            for D in range(10):

                if A+B+C+D == X:
                    for i in range(H):
                        for j in range(W):
                            if i % 3 == 2 or j % 3 == 2:
                                ans[i][j] = 0
                            elif i % 3 == j % 3 == 0:
                                ans[i][j] = A
                            elif i % 3 == 0 and j % 3 == 1:
                                ans[i][j] = B
                            elif i % 3 == 1 and j % 3 == 0:
                                ans[i][j] = C
                            else:
                                ans[i][j] = D
                    sol(ans)
                    print (-1)
                    sys.exit()
                    #print (ans)

print (-1)
0