結果
問題 | No.1434 Make Maze |
ユーザー |
|
提出日時 | 2021-03-19 23:54:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 2,180 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 91,996 KB |
最終ジャッジ日時 | 2024-11-24 21:46:46 |
合計ジャッジ時間 | 5,301 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
import sysinput = lambda : sys.stdin.readline().rstrip()sys.setrecursionlimit(2*10**5+10)write = lambda x: sys.stdout.write(x+"\n")debug = lambda x: sys.stderr.write(x+"\n")U = 0D = 1L = 2R = 3d = {U: "U",D:"D",L:"L",R:"R"}H,W,x = list(map(int, input().split()))h = (H+1)//2w = (W+1)//2M = h*w-1 if h*w%4==0 else h*wif not (H+W-2<=x<=2*(M-1) and x%2==0 and (x-(H+W-2))%4==0):print(-1)else:ans = [[0]*W for _ in range(H)]for i in range(1,H,2):for j in range(1,W,2):ans[i][j] = 1for i in range(H):for j in range(1,W,2):ans[i][j] = 1vals = []def sub0(h,w,v):if w==2:if v%2==1:return Nonenokori = h-1i = 0j = W-2while v>0:v -= 2vals.extend([R, D, L, D])ans[i][j] = 0ans[i+2][j] = 0ans[i+1][j-1] = 1ans[i+3][j+1] = 1nokori -= 1i += 4for _ in range(nokori):vals.append(D)vals.append(R)ans[-1][W-2] = 0return 0else:vals.extend([D]*(h-1)+[R])ans[-1][W-2*(w-1)] = 0# print(vals, W-2*(w-1))return sub1(h,w-1,v)def sub1(h,w,v):if v==0:vals.extend([R]*(w-1))for j in range(W-2*(w-1), W):ans[-1][j] = 0return 0elif v<=2*(h-1):# assert w>=2 and v%2==0vv = v//2vals.extend([U]*vv)vals.append(R)vals.extend([D]*vv)vals.extend([R]*(w-2))ans[H-1-vv*2][W-2*w+2] = 0# print(vv)for j in range(W-2*w+4,W):ans[-1][j] = 0return 0else:vals.extend([U]*(h-1))vals.append([R])ans[0][W-2*(w-1)] = 0return sub0(h,w-1,v-2*(h-1))v = x//2-(h-1+w-1)sub0(h,w,v)for l in ans:write("".join(["#" if l[i] else "." for i in range(len(l))]))