結果

問題 No.1916 Making Palindrome on Gird
ユーザー sotanishysotanishy
提出日時 2022-04-29 21:40:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 272,744 KB
最終ジャッジ日時 2023-09-11 12:36:06
合計ジャッジ時間 17,766 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
76,284 KB
testcase_01 AC 98 ms
71,596 KB
testcase_02 AC 123 ms
77,908 KB
testcase_03 AC 98 ms
71,468 KB
testcase_04 AC 102 ms
76,276 KB
testcase_05 AC 103 ms
76,468 KB
testcase_06 AC 102 ms
76,324 KB
testcase_07 AC 105 ms
76,108 KB
testcase_08 AC 101 ms
76,464 KB
testcase_09 AC 102 ms
76,004 KB
testcase_10 AC 97 ms
71,660 KB
testcase_11 AC 103 ms
75,988 KB
testcase_12 WA -
testcase_13 AC 122 ms
78,000 KB
testcase_14 AC 119 ms
78,008 KB
testcase_15 WA -
testcase_16 AC 274 ms
86,184 KB
testcase_17 AC 537 ms
117,976 KB
testcase_18 AC 1,770 ms
266,828 KB
testcase_19 AC 1,697 ms
267,208 KB
testcase_20 AC 1,710 ms
266,864 KB
testcase_21 AC 1,760 ms
265,588 KB
testcase_22 AC 1,739 ms
266,216 KB
testcase_23 AC 99 ms
71,708 KB
testcase_24 AC 97 ms
71,752 KB
testcase_25 AC 98 ms
71,508 KB
testcase_26 AC 97 ms
71,840 KB
testcase_27 AC 96 ms
71,668 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod = 10**9 + 7
H, W = map(int, input().split())
S = [input().rstrip() for _ in range(H)]
if S[0][0] != S[H-1][W-1]:
    print(0)
    exit()
dp = {(0, 0, H-1, W-1): 1}
for k in range((H+W-1)//2):
    ndp = defaultdict(int)
    for (i, j, k, l), w in dp.items():
        w %= mod
        for di, dj in [(1, 0), (0, 1)]:
            ni, nj = i+di, j+dj
            if ni < 0 or H <= ni or nj < 0 or W <= nj:
                continue
            for dk, dl in [(-1, 0), (0, -1)]:
                nk, nl = k+dk, l+dl
                if nk < 0 or H <= nk or nl < 0 or W <= nl:
                    continue
                if S[ni][nj] == S[nk][nl]:
                    ndp[(ni, nj, nk, nl)] += w
    dp = ndp

ans = 0
if (H+W-1)%2:
    for (i, j, k, l), w in dp.items():
        if (i, j) == (k, l):
            ans = (ans + w) % mod
else:
    for (i, j, k, l), w in dp.items():
        if abs(i-k)+abs(j-l) == 1:
            ans = (ans + w) % mod
print(ans)

0