結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,956 KB
testcase_01 AC 67 ms
71,168 KB
testcase_02 AC 78 ms
75,964 KB
testcase_03 AC 70 ms
70,940 KB
testcase_04 AC 71 ms
71,176 KB
testcase_05 AC 72 ms
71,132 KB
testcase_06 AC 644 ms
80,624 KB
testcase_07 AC 677 ms
81,356 KB
testcase_08 AC 638 ms
80,796 KB
testcase_09 WA -
testcase_10 AC 659 ms
81,308 KB
testcase_11 AC 1,073 ms
81,972 KB
testcase_12 AC 669 ms
81,220 KB
testcase_13 AC 853 ms
81,180 KB
testcase_14 AC 580 ms
80,604 KB
testcase_15 AC 2,602 ms
82,040 KB
testcase_16 AC 246 ms
80,144 KB
testcase_17 AC 581 ms
80,544 KB
testcase_18 AC 392 ms
80,532 KB
testcase_19 AC 591 ms
80,544 KB
testcase_20 AC 487 ms
80,024 KB
testcase_21 AC 241 ms
80,204 KB
testcase_22 WA -
testcase_23 AC 2,611 ms
81,880 KB
testcase_24 AC 706 ms
81,344 KB
testcase_25 AC 636 ms
81,156 KB
testcase_26 AC 243 ms
80,052 KB
testcase_27 WA -
testcase_28 AC 656 ms
81,220 KB
testcase_29 AC 242 ms
80,228 KB
testcase_30 AC 645 ms
81,088 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)

print ("4",file=sys.stderr)
#type4
cnt = 0
for D in range(10):
    for C in range(10):
        for B in range(10):
            for A 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)
                    cnt += 1
                    if cnt >= 30:
                        print (-1)
                        sys.exit()
print (-1)
0