結果

問題 No.1916 Making Palindrome on Gird
ユーザー とりゐとりゐ
提出日時 2022-02-22 01:33:16
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 843 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 269,212 KB
最終ジャッジ日時 2023-09-12 21:22:01
合計ジャッジ時間 19,965 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
76,244 KB
testcase_01 AC 96 ms
71,500 KB
testcase_02 AC 134 ms
78,656 KB
testcase_03 AC 96 ms
71,740 KB
testcase_04 AC 101 ms
76,276 KB
testcase_05 AC 95 ms
71,528 KB
testcase_06 AC 102 ms
76,196 KB
testcase_07 AC 103 ms
76,208 KB
testcase_08 AC 103 ms
76,076 KB
testcase_09 AC 102 ms
76,228 KB
testcase_10 AC 94 ms
71,660 KB
testcase_11 AC 101 ms
76,244 KB
testcase_12 AC 102 ms
76,168 KB
testcase_13 AC 132 ms
79,004 KB
testcase_14 AC 131 ms
78,892 KB
testcase_15 AC 467 ms
90,356 KB
testcase_16 AC 303 ms
82,044 KB
testcase_17 AC 850 ms
116,852 KB
testcase_18 AC 2,070 ms
200,888 KB
testcase_19 AC 2,015 ms
198,016 KB
testcase_20 AC 2,063 ms
200,720 KB
testcase_21 AC 2,091 ms
203,160 KB
testcase_22 AC 2,002 ms
198,932 KB
testcase_23 AC 110 ms
77,604 KB
testcase_24 AC 104 ms
76,536 KB
testcase_25 AC 102 ms
76,572 KB
testcase_26 AC 102 ms
76,700 KB
testcase_27 AC 98 ms
72,772 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
mod=10**9+7

h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(list(input()))

dp=defaultdict(int)
if (h+w)%2==0:
  for i1 in range(h):
    j1=(h+w-2)//2-i1
    if 0<=j1<w:
      dp[(i1,j1,i1,j1)]=1
else:
  for i1 in range(h):
    j1=(h+w-3)//2-i1
    if 0<=j1<w:
      for i2,j2 in [(i1+1,j1),(i1,j1+1)]:
        if 0<=i2<h and 0<=j2<w and s[i1][j1]==s[i2][j2]:
          dp[(i1,j1,i2,j2)]=1

for _ in range((h+w-2)//2):
  dp_new=defaultdict(int)
  for i1,j1,i2,j2 in dp:
    for ni1,nj1,ni2,nj2 in [(i1-1,j1,i2+1,j2),(i1,j1-1,i2+1,j2),(i1-1,j1,i2,j2+1),(i1,j1-1,i2,j2+1)]:
      if 0<=ni1<h and 0<=nj1<w and 0<=ni2<h and 0<=nj2<w and s[ni1][nj1]==s[ni2][nj2]:
        dp_new[(ni1,nj1,ni2,nj2)]+=dp[(i1,j1,i2,j2)]
        dp_new[(ni1,nj1,ni2,nj2)]%=mod
  dp=dp_new
  
print(dp[(0,0,h-1,w-1)])
0