結果
問題 | No.1434 Make Maze |
ユーザー | chineristAC |
提出日時 | 2021-01-10 16:36:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 8,897 bytes |
コンパイル時間 | 477 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 95,080 KB |
最終ジャッジ日時 | 2024-11-24 21:36:13 |
合計ジャッジ時間 | 6,502 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
55,152 KB |
testcase_01 | AC | 36 ms
54,456 KB |
testcase_02 | AC | 153 ms
94,868 KB |
testcase_03 | AC | 151 ms
95,080 KB |
testcase_04 | AC | 37 ms
54,472 KB |
testcase_05 | AC | 36 ms
53,840 KB |
testcase_06 | AC | 35 ms
54,564 KB |
testcase_07 | AC | 36 ms
54,656 KB |
testcase_08 | AC | 35 ms
55,300 KB |
testcase_09 | AC | 37 ms
55,732 KB |
testcase_10 | AC | 36 ms
54,952 KB |
testcase_11 | AC | 37 ms
54,848 KB |
testcase_12 | AC | 62 ms
72,916 KB |
testcase_13 | AC | 38 ms
56,472 KB |
testcase_14 | AC | 71 ms
76,360 KB |
testcase_15 | AC | 93 ms
79,396 KB |
testcase_16 | AC | 74 ms
77,160 KB |
testcase_17 | AC | 65 ms
74,688 KB |
testcase_18 | AC | 84 ms
78,852 KB |
testcase_19 | AC | 110 ms
84,540 KB |
testcase_20 | AC | 36 ms
54,556 KB |
testcase_21 | AC | 37 ms
54,292 KB |
testcase_22 | AC | 36 ms
55,020 KB |
testcase_23 | AC | 34 ms
55,152 KB |
testcase_24 | AC | 106 ms
84,196 KB |
testcase_25 | AC | 132 ms
92,092 KB |
testcase_26 | AC | 76 ms
76,788 KB |
testcase_27 | AC | 96 ms
84,196 KB |
testcase_28 | AC | 75 ms
76,892 KB |
testcase_29 | AC | 53 ms
69,940 KB |
testcase_30 | AC | 82 ms
78,516 KB |
testcase_31 | AC | 94 ms
78,112 KB |
ソースコード
H,W,X = map(int,input().split()) h = (H+1)//2 w = (W+1)//2 if not 2*h+2*w-4<=X<=2*h*w-2: exit(print(-1)) diff = X - (2*h+2*w-4) if diff%4!=0: exit(print(-1)) if w%2==1: ans = [["." for j in range(W)] for i in range(H)] pos = (0,0) rest_dist = X ans[0][0] = "T" while pos!=(H-1,W-1): x,y = pos if rest_dist != (H-1-x) + (W-1-y): if x==0: if (y//2)%2==1: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) elif x==H-1: if (y//2)%2==0: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) elif (y//2)%2==0: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) rest_dist -= 2 else: while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) while pos[0]!=H-1: x,y = pos ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) stack = [(i,j) for i in range(H) for j in range(W) if ans[i][j]=="T" and i%2==0 and j%2==0] while stack: x,y = stack.pop() if x+2<=H-1 and ans[x+2][y]!="T": ans[x+2][y] = "T" ans[x+1][y] = "T" stack.append((x+2,y)) if 2<=x and ans[x-2][y]!="T": ans[x-2][y] = "T" ans[x-1][y] = "T" stack.append((x-2,y)) if y+2<=W-1 and ans[x][y+2]!="T": ans[x][y+2] = "T" ans[x][y+1] = "T" stack.append((x,y+2)) if 2<=y and ans[x][y-2]!="T": ans[x][y-2] = "T" ans[x][y-1] = "T" stack.append((x,y-2)) for i in range(H): for j in range(W): if ans[i][j]=="T": ans[i][j]="." else: ans[i][j]="#" print("".join(ans[i])) elif h%2==1: H,W = W,H h,w = w,h ans = [["." for j in range(W)] for i in range(H)] pos = (0,0) rest_dist = X ans[0][0] = "T" while pos!=(H-1,W-1): x,y = pos if rest_dist != (H-1-x) + (W-1-y): if x==0: if (y//2)%2==1: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) elif x==H-1: if (y//2)%2==0: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) elif (y//2)%2==0: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) rest_dist -= 2 else: while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) while pos[0]!=H-1: x,y = pos ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) stack = [(i,j) for i in range(H) for j in range(W) if ans[i][j]=="T" and i%2==0 and j%2==0] while stack: x,y = stack.pop() if x+2<=H-1 and ans[x+2][y]!="T": ans[x+2][y] = "T" ans[x+1][y] = "T" stack.append((x+2,y)) if 2<=x and ans[x-2][y]!="T": ans[x-2][y] = "T" ans[x-1][y] = "T" stack.append((x-2,y)) if y+2<=W-1 and ans[x][y+2]!="T": ans[x][y+2] = "T" ans[x][y+1] = "T" stack.append((x,y+2)) if 2<=y and ans[x][y-2]!="T": ans[x][y-2] = "T" ans[x][y-1] = "T" stack.append((x,y-2)) for i in range(H): for j in range(W): if ans[i][j]=="T": ans[i][j]="." else: ans[i][j]="#" rev = [[ans[j][i] for j in range(H)] for i in range(W)] for i in range(W): print("".join(rev[i])) else: ans = [["." for j in range(W)] for i in range(H)] pos = (0,0) rest_dist = X ans[0][0] = "T" while pos!=(H-1,W-1): x,y = pos if rest_dist != (H-1-x) + (W-1-y): if y==W-3: if (x//2)%2==0: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) elif y==W-1: if (x//2)%2==0: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) else: ans[x][y-1] = "T" ans[x][y-2] = "T" pos = (x,y-2) else: if x==0: if (y//2)%2==1: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) elif x==H-1: if (y//2)%2==0: ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) elif (y//2)%2==0: ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) else: ans[x-1][y] = "T" ans[x-2][y] = "T" pos = (x-2,y) rest_dist -= 2 else: if y==W-3: if (x//2)%2==0: while pos[0]!=H-1: x,y = pos ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: while pos[0]!=H-1: x,y = pos ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) elif y==W-1: while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) else: while pos[1]!=W-1: x,y = pos ans[x][y+1] = "T" ans[x][y+2] = "T" pos = (x,y+2) while pos[0]!=H-1: x,y = pos ans[x+1][y] = "T" ans[x+2][y] = "T" pos = (x+2,y) stack = [(i,j) for i in range(H) for j in range(W) if ans[i][j]=="T" and i%2==0 and j%2==0] while stack: x,y = stack.pop() if x+2<=H-1 and ans[x+2][y]!="T": ans[x+2][y] = "T" ans[x+1][y] = "T" stack.append((x+2,y)) if 2<=x and ans[x-2][y]!="T": ans[x-2][y] = "T" ans[x-1][y] = "T" stack.append((x-2,y)) if y+2<=W-1 and ans[x][y+2]!="T": ans[x][y+2] = "T" ans[x][y+1] = "T" stack.append((x,y+2)) if 2<=y and ans[x][y-2]!="T": ans[x][y-2] = "T" ans[x][y-1] = "T" stack.append((x,y-2)) for i in range(H): for j in range(W): if ans[i][j]=="T": ans[i][j]="." else: ans[i][j]="#" print("".join(ans[i]))