結果

問題 No.1916 Making Palindrome on Gird
ユーザー kozy
提出日時 2022-04-29 21:39:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 487 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 414,844 KB
最終ジャッジ日時 2024-06-29 02:59:04
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
def ans(a,b,c,d):
  if not (0<=a<H and 0<=b<W and 0<=c<H and 0<=d<W):
    return 0
  if (a,b,c,d) in D:
    return D[(a,b,c,d)]
  x=0
  if L[a][b]!=L[c][d]:
    return 0
  if (a,b)==(c,d):
    return 1
  if (a+1,b)==(c,d) or (a,b+1)==(c,d):
    return 1
  X=(ans(a+1,b,c-1,d)+ans(a,b+1,c,d-1)+ans(a,b+1,c-1,d)+ans(a+1,b,c,d-1))%mod
  D[(a,b,c,d)]=X
  return X
H,W=map(int,input().split())
L=list()
for i in range(H):
  S=input()
  L.append(S)
D=dict()
print(ans(0,0,H-1,W-1))
0