結果
問題 | No.1434 Make Maze |
ユーザー | chineristAC |
提出日時 | 2021-01-10 16:36:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 8,897 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,848 KB |
実行使用メモリ | 95,324 KB |
最終ジャッジ日時 | 2024-05-03 18:09:47 |
合計ジャッジ時間 | 6,762 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,440 KB |
testcase_01 | AC | 41 ms
53,972 KB |
testcase_02 | AC | 171 ms
95,324 KB |
testcase_03 | AC | 169 ms
95,300 KB |
testcase_04 | AC | 42 ms
55,888 KB |
testcase_05 | AC | 41 ms
54,364 KB |
testcase_06 | AC | 42 ms
55,804 KB |
testcase_07 | AC | 40 ms
55,088 KB |
testcase_08 | AC | 41 ms
54,800 KB |
testcase_09 | AC | 41 ms
54,596 KB |
testcase_10 | AC | 40 ms
55,040 KB |
testcase_11 | AC | 42 ms
55,520 KB |
testcase_12 | AC | 71 ms
74,308 KB |
testcase_13 | AC | 43 ms
55,936 KB |
testcase_14 | AC | 83 ms
76,508 KB |
testcase_15 | AC | 102 ms
79,424 KB |
testcase_16 | AC | 85 ms
76,748 KB |
testcase_17 | AC | 74 ms
75,124 KB |
testcase_18 | AC | 96 ms
79,104 KB |
testcase_19 | AC | 119 ms
84,492 KB |
testcase_20 | AC | 40 ms
54,492 KB |
testcase_21 | AC | 41 ms
54,392 KB |
testcase_22 | AC | 40 ms
55,264 KB |
testcase_23 | AC | 41 ms
55,688 KB |
testcase_24 | AC | 122 ms
84,512 KB |
testcase_25 | AC | 147 ms
92,264 KB |
testcase_26 | AC | 87 ms
76,752 KB |
testcase_27 | AC | 107 ms
83,824 KB |
testcase_28 | AC | 88 ms
76,880 KB |
testcase_29 | AC | 63 ms
68,640 KB |
testcase_30 | AC | 92 ms
79,108 KB |
testcase_31 | AC | 95 ms
78,260 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]))