結果

問題 No.1434 Make Maze
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-08 15:04:53
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,688 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 92,544 KB
最終ジャッジ日時 2024-05-05 00:22:39
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,224 KB
testcase_01 AC 40 ms
52,736 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 38 ms
52,608 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 36 ms
52,352 KB
testcase_07 AC 38 ms
52,736 KB
testcase_08 WA -
testcase_09 AC 37 ms
51,968 KB
testcase_10 RE -
testcase_11 AC 43 ms
52,608 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 37 ms
52,352 KB
testcase_21 AC 37 ms
52,480 KB
testcase_22 AC 38 ms
52,608 KB
testcase_23 AC 39 ms
52,480 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,x=map(int,input().split())
min_x=h+w-2
max_x=min_x+max((h-1)*(w//4)*2,(w-1)*(h//4)*2)
if min_x <= x <= max_x and (x-min_x)%4==0:
  mat=[["#"]*w for _ in range(h)]
  for i in range(0,h,2):
    for j in range(0,w,2):
      mat[i][j]="x"
  if (h-1)*(w//4)*2>(w-1)*(h//4)*2:
    # 上下に振りながら右に行く
    # 壁にぶつかるまでは下または上に行く。ぶつかったときのみ右に行く
    seen=[[-1]*w for _ in range(h)]
    seen[0][0]=0
    for i in range(h):
      seen[i][0]=i
      mat[i][0]="."
    todo=[[i,0]]
    while todo:
      i,j=todo.pop()
      mat[i][j]="."
      if [i,j]==[h-1,w-1]:break
      if seen[i][j]+(h-i-1)+(w-j-1)==x:
        # ここからは最短距離を歩く
        # 右に行けるだけ右に行く
        while [i,j]!=[h-1,w-1]:
          if j+1<w:
            j+=1
          else:
            i+=1
          mat[i][j]="."
        break
      elif i+1<h and seen[i+1][j]==-1:
        # 下にいく
        seen[i+1][j]=seen[i][j]+1
        todo.append([i+1,j])
      elif 0<=i-1 and seen[i-1][j]==-1:
        # 上にいく
        seen[i-1][j]=seen[i][j]+1
        todo.append([i-1,j])
      else:
        # 右に行く
        seen[i][j+1]=seen[i][j]+1
        mat[i][j+1]="."
        seen[i][j+2]=seen[i][j]+2
        todo.append([i,j+2])
    for i in range(h):
      for j in range(w):
        if mat[i][j]=="x":
          mat[i][j]="."
          mat[i+1][j]="."
  else:
    # 左右に振りながら上に行く
    # 壁にぶつかるまでは右または左に行く。ぶつかったときのみ下に行く
    seen=[[-1]*w for _ in range(h)]
    seen[0][0]=0
    for i in range(w):
      seen[0][i]=i
      mat[0][i]="."
    todo=[[0,i]]

    while todo:
      i,j=todo.pop()
      mat[i][j]="."
      if [i,j]==[h-1,w-1]:break
      if seen[i][j]+(h-i-1)+(w-j-1)==x:
        # ここからは最短距離を歩く
        # 下に行けるだけ下に行く
        while [i,j]!=[h-1,w-1]:
          if i+1<h:
            i+=1
          else:
            j+=1
          mat[i][j]="."
        break
      elif j+1<w and seen[i][j+1]==-1:
        # 右にいく
        seen[i][j+1]=seen[i][j]+1
        todo.append([i,j+1])
      elif 0<=j-1 and seen[i][j-1]==-1:
        # 左にいく
        seen[i][j-1]=seen[i][j]+1
        todo.append([i,j-1])
      else:
        # 下に行く
        seen[i+1][j]=seen[i][j]+1
        mat[i+1][j]="."
        seen[i+2][j]=seen[i][j]+2
        todo.append([i+2,j])
    for i in range(h):
      for j in range(w):
        pass
        if mat[i][j]=="x":
          mat[i][j]="."
          mat[i][j+1]="."

  for x in mat:
    print("".join(x))
else:
  print(-1)
0