結果

問題 No.1916 Making Palindrome on Gird
ユーザー kozykozy
提出日時 2022-04-30 00:45:56
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,080 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 584,480 KB
最終ジャッジ日時 2023-09-11 16:34:42
合計ジャッジ時間 12,912 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,216 KB
testcase_01 AC 71 ms
71,092 KB
testcase_02 AC 125 ms
77,256 KB
testcase_03 AC 77 ms
74,552 KB
testcase_04 AC 82 ms
75,672 KB
testcase_05 AC 82 ms
75,648 KB
testcase_06 AC 92 ms
76,704 KB
testcase_07 AC 92 ms
76,608 KB
testcase_08 AC 92 ms
76,464 KB
testcase_09 AC 83 ms
75,956 KB
testcase_10 AC 71 ms
71,120 KB
testcase_11 AC 92 ms
76,616 KB
testcase_12 AC 75 ms
74,888 KB
testcase_13 AC 1,394 ms
316,080 KB
testcase_14 AC 936 ms
250,524 KB
testcase_15 AC 2,061 ms
361,932 KB
testcase_16 AC 1,439 ms
277,168 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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:
          dp[(a,b,c,d)]=0
          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
              continue
            else:
              if a!=H-1:
                if c!=0:
                  dp[(a,b,c,d)]+=dp[(a+1,b,c-1,d)]
                if d!=0:
                  dp[(a,b,c,d)]+=dp[(a+1,b,c,d-1)]
              if b!=W-1:
                if c!=0:
                  dp[(a,b,c,d)]+=dp[(a,b+1,c-1,d)]
                if d!=0:
                  dp[(a,b,c,d)]+=dp[(a,b+1,c,d-1)]
              dp[(a,b,c,d)]%=mod
          else:
            dp[(i,k-i,H-1-j,W-1-(k-j))]=0
  print(dp[(0,0,H-1,W-1)])
main()
0