結果

問題 No.1916 Making Palindrome on Gird
ユーザー titiatitia
提出日時 2022-04-29 22:11:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,352 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 269,192 KB
最終ジャッジ日時 2023-09-11 13:26:08
合計ジャッジ時間 29,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
75,992 KB
testcase_01 AC 95 ms
71,764 KB
testcase_02 AC 186 ms
82,924 KB
testcase_03 AC 93 ms
71,612 KB
testcase_04 AC 100 ms
75,988 KB
testcase_05 AC 99 ms
75,992 KB
testcase_06 AC 100 ms
76,064 KB
testcase_07 AC 100 ms
76,064 KB
testcase_08 AC 99 ms
76,280 KB
testcase_09 AC 100 ms
76,040 KB
testcase_10 AC 94 ms
71,748 KB
testcase_11 AC 100 ms
76,060 KB
testcase_12 AC 100 ms
76,216 KB
testcase_13 AC 164 ms
79,028 KB
testcase_14 AC 129 ms
78,356 KB
testcase_15 AC 908 ms
109,080 KB
testcase_16 AC 809 ms
101,360 KB
testcase_17 AC 1,349 ms
143,648 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 94 ms
71,680 KB
testcase_24 AC 93 ms
71,872 KB
testcase_25 AC 96 ms
71,488 KB
testcase_26 AC 96 ms
71,740 KB
testcase_27 AC 95 ms
71,748 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict

mod=10**9+7

H,W=map(int,input().split())
MAP=[input().strip() for i in range(H)]

if MAP[0][0]!=MAP[-1][-1]:
    print(0)
    exit()

DP=dict()
DP[0,0,H-1,W-1]=1

for i in range((H+W-2)//2):
    NDP=defaultdict(int)

    for x,y,z,w in DP:
        if 0<=x<H and 0<=z<H and 0<=y+1<W and 0<=w-1<W and MAP[x][y+1]==MAP[z][w-1]:
            NDP[x,y+1,z,w-1]+=DP[x,y,z,w]
            NDP[x,y+1,z,w-1]%=mod

        if 0<=x<H and 0<=z-1<H and 0<=y+1<W and 0<=w<W and MAP[x][y+1]==MAP[z-1][w]:
            NDP[x,y+1,z-1,w]+=DP[x,y,z,w]
            NDP[x,y+1,z-1,w]%=mod

        if 0<=x+1<H and 0<=z<H and 0<=y<W and 0<=w-1<W and MAP[x+1][y]==MAP[z][w-1]:
            NDP[x+1,y,z,w-1]+=DP[x,y,z,w]
            NDP[x+1,y,z,w-1]%=mod

        if 0<=x+1<H and 0<=z-1<H and 0<=y<W and 0<=w<W and MAP[x+1][y]==MAP[z-1][w]:
            NDP[x+1,y,z-1,w]+=DP[x,y,z,w]
            NDP[x+1,y,z-1,w]%=mod
    DP=NDP

if (H+W)%2==0:
    ANS=0
    for x,y,z,w in DP:
        if x==z and y==w:
            ANS+=DP[x,y,z,w]
            ANS%=mod
    print(ANS)
    
else:
    ANS=0
    for x,y,z,w in DP:
        if x==z and y+1==w:
            ANS+=DP[x,y,z,w]
            ANS%=mod
        if x+1==z and y==w:
            ANS+=DP[x,y,z,w]
            ANS%=mod
            
    print(ANS)
    
    
0