結果

問題 No.1916 Making Palindrome on Gird
ユーザー とりゐとりゐ
提出日時 2022-02-22 01:36:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 647 ms / 3,000 ms
コード長 920 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 141,944 KB
最終ジャッジ日時 2023-09-12 21:21:18
合計ジャッジ時間 14,547 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,600 KB
testcase_01 AC 73 ms
71,344 KB
testcase_02 AC 108 ms
77,100 KB
testcase_03 AC 73 ms
71,396 KB
testcase_04 AC 93 ms
76,480 KB
testcase_05 AC 88 ms
76,528 KB
testcase_06 AC 91 ms
76,368 KB
testcase_07 AC 89 ms
76,308 KB
testcase_08 AC 100 ms
76,836 KB
testcase_09 AC 73 ms
71,428 KB
testcase_10 AC 73 ms
71,192 KB
testcase_11 AC 90 ms
76,272 KB
testcase_12 AC 85 ms
76,788 KB
testcase_13 AC 312 ms
100,372 KB
testcase_14 AC 236 ms
92,664 KB
testcase_15 AC 355 ms
106,612 KB
testcase_16 AC 283 ms
94,348 KB
testcase_17 AC 610 ms
132,820 KB
testcase_18 AC 638 ms
141,756 KB
testcase_19 AC 624 ms
141,664 KB
testcase_20 AC 634 ms
141,568 KB
testcase_21 AC 639 ms
141,708 KB
testcase_22 AC 647 ms
141,568 KB
testcase_23 AC 538 ms
140,748 KB
testcase_24 AC 532 ms
140,740 KB
testcase_25 AC 522 ms
140,992 KB
testcase_26 AC 521 ms
141,624 KB
testcase_27 AC 522 ms
141,188 KB
testcase_28 AC 619 ms
141,668 KB
testcase_29 AC 608 ms
141,700 KB
testcase_30 AC 603 ms
141,748 KB
testcase_31 AC 622 ms
141,944 KB
testcase_32 AC 613 ms
141,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7

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

def conv(i,j,k):
  return h*w*i+h*j+k

dp=[0]*(h*w*h)
if (h+w)%2==0:
  for i1 in range(h):
    j1=(h+w-2)//2-i1
    if 0<=j1<w:
      dp[conv(i1,j1,i1)]=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[conv(i1,j1,i2)]=1

for m in range((h+w-2)//2,0,-1):
  for i1 in range(h):
    j1=m-i1
    if 0<=j1<w:
      for i2 in range(h):
        j2=h+w-2-m-i2
        if 0<=j2<w:
          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[conv(ni1,nj1,ni2)]+=dp[conv(i1,j1,i2)]
              dp[conv(ni1,nj1,ni2)]%=mod
  
print(dp[conv(0,0,h-1)])
0