結果

問題 No.1434 Make Maze
ユーザー tyawanmusityawanmusi
提出日時 2021-01-10 16:38:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 16,308 KB
最終ジャッジ日時 2023-08-16 09:22:58
合計ジャッジ時間 7,889 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,488 KB
testcase_01 AC 16 ms
8,496 KB
testcase_02 AC 54 ms
16,308 KB
testcase_03 AC 54 ms
16,124 KB
testcase_04 AC 17 ms
8,296 KB
testcase_05 AC 16 ms
8,492 KB
testcase_06 AC 17 ms
8,500 KB
testcase_07 AC 17 ms
8,420 KB
testcase_08 AC 17 ms
8,504 KB
testcase_09 AC 16 ms
8,420 KB
testcase_10 AC 17 ms
8,336 KB
testcase_11 AC 17 ms
8,476 KB
testcase_12 AC 19 ms
8,396 KB
testcase_13 AC 17 ms
8,476 KB
testcase_14 AC 18 ms
8,548 KB
testcase_15 AC 26 ms
10,308 KB
testcase_16 AC 19 ms
8,856 KB
testcase_17 AC 18 ms
8,592 KB
testcase_18 AC 21 ms
9,160 KB
testcase_19 AC 37 ms
12,540 KB
testcase_20 AC 17 ms
8,344 KB
testcase_21 AC 17 ms
8,348 KB
testcase_22 AC 16 ms
8,344 KB
testcase_23 AC 16 ms
8,460 KB
testcase_24 AC 28 ms
11,256 KB
testcase_25 AC 42 ms
13,192 KB
testcase_26 AC 19 ms
8,592 KB
testcase_27 AC 45 ms
11,016 KB
testcase_28 AC 19 ms
8,812 KB
testcase_29 AC 17 ms
8,076 KB
testcase_30 AC 27 ms
9,396 KB
testcase_31 AC 21 ms
8,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve1(h, w, x):
  if (x-(h-1)-(w-1))%4 != 0:
    return ["-1"]
  if not (h-1)+(w-1) <= x <= ((h//2+1)*(w//2+1)-1)*2:
    return ["-1"]
  ans = [["#"]*w for i in range(h)]
  for i in range(0, h, 2):
    ans[i] = ["."]*w
  for i in range(1, h, 4):
    ans[i][w-1] = "."
  x -= (h-1)+(w-1)
  for i in range(3, h, 4):
    y = min(x//2, w-1)
    ans[i][(w-1)-y] = "."
    x -= y*2
  return ans

def solve2(h, w, x):
  if (x-(h-1)-(w-1))%4 != 0:
    return ["-1"]
  if not (h-1)+(w-1) <= x <= ((h//2+1)*(w//2+1)-2)*2:
    return ["-1"]
  ans = [["#"]*w for i in range(h)]

  if (h-3)+(2*(w//2+1)-2)*2 <= x:
    ans[0][0] = ans[0][w-1] ="."
    for j in range(2, w-4, 4):
      ans[0][j] = ans[0][j+1] = ans[0][j+2] = "."
    for j in range(0, w, 2):
      ans[1][j] = "."
    for j in range(0, w+1, 4):
      ans[2][j] = ans[2][j+1] = ans[2][j+2] = "."
    x -= (h-3)+(2*(w//2+1)-2)*2
  else:
    ans[0] = ["."]*w
    ans[1][w-1] = "."
    ans[2] = ["."]*w
    x -= (h-1)+(w-1)

  for i in range(4, h, 2):
    ans[i] = ["."]*w
  for i in range(3, h, 4):
    ans[i][w-1] = "."

  for i in range(5, h, 4):
    y = min(x//2, w-1)
    ans[i][(w-1)-y] = "."
    x -= y*2
  return ans


h, w, x = map(int, input().split())
if h%4 == 3:
  if w%4 == 3:
    ans = solve2(h, w, x)
    for i in ans:
      print("".join(i))
  else:
    ans = solve1(w, h, x)
    if len(ans) == 1:
      print(-1)
    else:
      for i in range(h):
        print("".join([ans[j][i] for j in range(w)]))
else:
  ans = solve1(h, w, x)
  for i in ans:
    print("".join(i))
0