結果

問題 No.1916 Making Palindrome on Gird
ユーザー kozykozy
提出日時 2022-04-29 22:13:22
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 711 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 663,348 KB
最終ジャッジ日時 2023-09-11 13:29:50
合計ジャッジ時間 48,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,196 KB
testcase_01 AC 74 ms
71,336 KB
testcase_02 AC 95 ms
76,844 KB
testcase_03 AC 74 ms
71,156 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 72 ms
71,004 KB
testcase_11 RE -
testcase_12 RE -
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 #

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):
      if 0<=H-1-j<H and 0<=W-1-(k-j)<W:
        if L[i][k-i]==L[H-1-j][W-1-(k-j)]:
          a=i
          b=k-i
          c=H-1-j
          d=W-1-(k-j)
          if not (a<=c and b<=d):
              dp[(a,b,c,d)]=0
              continue
          if k==((H+W)//2)-1:
            dp[(i,k-i,H-1-j,W-1-(k-j))]=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)])
0