結果

問題 No.1916 Making Palindrome on Gird
ユーザー kozykozy
提出日時 2022-04-29 22:19:33
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 750 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 641,636 KB
最終ジャッジ日時 2023-09-11 13:39:56
合計ジャッジ時間 46,437 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,100 KB
testcase_01 AC 71 ms
71,364 KB
testcase_02 AC 85 ms
76,228 KB
testcase_03 AC 69 ms
71,328 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 68 ms
71,256 KB
testcase_11 RE -
testcase_12 AC 73 ms
75,052 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  H,W=map(int,input().split())
  L=list()
  for i in range(H):
    S=input()
    L.append(S)
  mod=10**9+7
  dp=dict()
  for k in range(((H+W)//2)-1,-1,-1):
    #k:距離
    for i in range(k+1):
      for j in range(k+1):
        a=i
        b=k-i
        c=H-1-j
        d=W-1-(k-j)
        if 0<=a<H and 0<=b<W and 0<=c<H and 0<=d<W:
          if L[a][b]==L[c][d]:
            if not (a<=c and b<=d):
                dp[(a,b,c,d)]=0
                continue
            if k==((H+W)//2)-1:
              dp[(a,b,c,d)]=1
            else:
              dp[(a,b,c,d)]=(dp[(a+1,b,c-1,d)]+dp[(a,b+1,c,d-1)]+dp[(a,b+1,c-1,d)]+dp[(a+1,b,c,d-1)])%mod
          else:
            dp[(i,k-i,H-1-j,W-1-(k-j))]=0
  print(dp[(0,0,H-1,W-1)])
main()
0