結果

問題 No.1916 Making Palindrome on Gird
ユーザー ああいい
提出日時 2022-04-29 21:44:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 259,028 KB
最終ジャッジ日時 2024-06-29 03:05:23
合計ジャッジ時間 9,746 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 6 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
S = [input() for _ in range(H)]
P = 10 ** 9 + 7

import sys
if S[0][0] != S[-1][-1]:
    print(0)
    exit()
from collections import defaultdict
d = defaultdict(int)
d[(0,0,H - 1,W - 1)] = 1
ans = 0
for _ in range(H + W - 2):
    nx = defaultdict(int)
    for h,w,hh,ww in d:
        if h == hh and w == ww:
            ans += d[(h,w,hh,ww)]
            ans %= P
            continue
        for i,j in [(1,0),(0,1)]:
            for k,l in [(-1,0),(0,-1)]:
                if h + i < H and w + j < W and hh + k >= 0 and ww + l >= 0:
                    if S[h + i][w + j] == S[hh + k][ww + l]:
                        nx[(h + i,w + j,hh + k,ww + l)] += d[(h,w,hh,ww)]
                        nx[(h + i,w + j,hh + k,ww + l)] %= P
    d = nx
print(ans)
0