結果

問題 No.1916 Making Palindrome on Gird
ユーザー titiatitia
提出日時 2022-04-29 21:55:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 269,300 KB
最終ジャッジ日時 2023-09-11 13:01:16
合計ジャッジ時間 29,355 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
76,180 KB
testcase_01 AC 92 ms
71,576 KB
testcase_02 AC 241 ms
83,152 KB
testcase_03 AC 96 ms
71,572 KB
testcase_04 AC 100 ms
76,280 KB
testcase_05 AC 100 ms
76,292 KB
testcase_06 AC 104 ms
76,024 KB
testcase_07 AC 101 ms
76,180 KB
testcase_08 AC 100 ms
76,068 KB
testcase_09 AC 101 ms
76,116 KB
testcase_10 AC 93 ms
71,688 KB
testcase_11 AC 102 ms
76,264 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 131 ms
78,416 KB
testcase_15 WA -
testcase_16 AC 825 ms
101,052 KB
testcase_17 AC 1,367 ms
143,732 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 95 ms
71,564 KB
testcase_24 AC 94 ms
71,580 KB
testcase_25 AC 93 ms
71,572 KB
testcase_26 AC 92 ms
71,444 KB
testcase_27 AC 95 ms
71,684 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<+1<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