結果

問題 No.1434 Make Maze
ユーザー titiatitia
提出日時 2021-03-19 23:28:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 106,496 KB
最終ジャッジ日時 2024-05-03 18:13:21
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,608 KB
testcase_01 AC 35 ms
52,352 KB
testcase_02 AC 269 ms
106,496 KB
testcase_03 AC 269 ms
106,276 KB
testcase_04 AC 36 ms
52,608 KB
testcase_05 AC 35 ms
52,864 KB
testcase_06 AC 34 ms
52,480 KB
testcase_07 AC 37 ms
52,224 KB
testcase_08 AC 37 ms
52,736 KB
testcase_09 AC 38 ms
52,480 KB
testcase_10 AC 36 ms
52,992 KB
testcase_11 AC 36 ms
53,120 KB
testcase_12 AC 85 ms
77,056 KB
testcase_13 AC 39 ms
53,504 KB
testcase_14 AC 85 ms
77,440 KB
testcase_15 AC 130 ms
82,616 KB
testcase_16 AC 91 ms
78,288 KB
testcase_17 AC 84 ms
76,880 KB
testcase_18 AC 98 ms
79,100 KB
testcase_19 AC 184 ms
89,984 KB
testcase_20 AC 37 ms
53,248 KB
testcase_21 AC 41 ms
55,296 KB
testcase_22 AC 39 ms
54,272 KB
testcase_23 AC 43 ms
59,392 KB
testcase_24 AC 134 ms
85,248 KB
testcase_25 AC 217 ms
94,336 KB
testcase_26 AC 89 ms
77,460 KB
testcase_27 AC 141 ms
84,208 KB
testcase_28 AC 88 ms
77,212 KB
testcase_29 AC 73 ms
73,472 KB
testcase_30 AC 96 ms
78,756 KB
testcase_31 AC 99 ms
78,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H,W,X=map(int,input().split())

ANS=[["."]*W for i in range(H)]
k=H-1+W-1
if X<k or (X-k)%4!=0:
    print(-1)
    exit()



for i in range(H):
    for j in range(W):
        if i%2==1 and j%2==1:
            ANS[i][j]="#"

for i in range(H):
    ANS[i][0]=0

for j in range(W):
    ANS[-1][j]=0

NOWX=1
NOWY=0
while k<X:
    if NOWX+2<H and NOWY+1<W:
        k+=4
        ANS[NOWX][NOWY]="."
        for i,j in [(NOWX-1,NOWY+1),(NOWX-1,NOWY+2),(NOWX,NOWY+2),(NOWX+1,NOWY+1),(NOWX+1,NOWY+2)]:
                    ANS[i][j]=0
        NOWY+=2


    elif NOWY+1==W:
        NOWX+=4
        NOWY=0

    else:
        break

if k<X and H%4==3:
    NOWX=H-1
    NOWY=3
    while k<X:
        if NOWY+1<W:
            k+=4
            ANS[NOWX][NOWY]="."
            for i,j in [(NOWX-1,NOWY-1),(NOWX-1,NOWY+1),(NOWX-2,NOWY-1),(NOWX-2,NOWY),(NOWX-2,NOWY+1)]:
                        ANS[i][j]=0
            NOWY+=4
        else:
            break

if k!=X:
    print(-1)
    exit()

for i in range(H):
    for j in range(W):
        if ANS[i][j]==".":
            flag=0
            for z,w in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
                if 0<=z<H and 0<=w<W and ANS[z][w]==0:
                    ANS[i][j]="#"


for j in range(W):
    if j%2==0 and ANS[H-3][j]==".":
        ANS[H-2][j]="."

for j in range(W):
    for i in range(H-2,-1,-1):
        if ANS[i][j]=="." and ANS[i+1][j]=="#":
            ANS[i][j]="#"

for i in range(H):
    for j in range(W):
        if ANS[i][j]==0:
            ANS[i][j]="."

for ans in ANS:
    print("".join(ans))
0