結果

問題 No.1916 Making Palindrome on Gird
ユーザー 👑 rin204rin204
提出日時 2022-05-04 18:45:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 888 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 269,676 KB
最終ジャッジ日時 2024-07-03 21:45:28
合計ジャッジ時間 19,648 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
60,076 KB
testcase_01 AC 37 ms
52,064 KB
testcase_02 AC 62 ms
75,984 KB
testcase_03 AC 36 ms
52,456 KB
testcase_04 AC 42 ms
58,788 KB
testcase_05 AC 40 ms
59,004 KB
testcase_06 AC 40 ms
59,736 KB
testcase_07 AC 40 ms
59,100 KB
testcase_08 AC 41 ms
57,848 KB
testcase_09 AC 40 ms
59,236 KB
testcase_10 AC 36 ms
53,504 KB
testcase_11 AC 45 ms
58,524 KB
testcase_12 AC 40 ms
58,144 KB
testcase_13 AC 59 ms
72,680 KB
testcase_14 AC 54 ms
70,364 KB
testcase_15 AC 336 ms
96,960 KB
testcase_16 AC 279 ms
89,576 KB
testcase_17 AC 652 ms
134,336 KB
testcase_18 AC 2,523 ms
263,536 KB
testcase_19 AC 2,333 ms
262,912 KB
testcase_20 AC 2,426 ms
263,252 KB
testcase_21 AC 2,475 ms
263,556 KB
testcase_22 AC 2,429 ms
263,412 KB
testcase_23 AC 40 ms
53,184 KB
testcase_24 AC 38 ms
54,492 KB
testcase_25 AC 38 ms
53,808 KB
testcase_26 AC 38 ms
53,756 KB
testcase_27 AC 38 ms
53,492 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

h, w = map(int, input().split())
S = [input() for _ in range(h)]

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

dp = {(0, 0, h - 1, w - 1): 1}
directions = [(1, 0, -1, 0), (0, 1, -1, 0), (1, 0, 0, -1), (0, 1, 0, -1)]

for _ in range((h + w) // 2 - 1):
    ndp = {}
    for (i1, j1, i2, j2), v in dp.items():
        for di1, dj1, di2, dj2 in directions:
            ni1 = i1 + di1
            nj1 = j1 + dj1
            ni2 = i2 + di2
            nj2 = j2 + dj2
            if ni1 == h or nj1 == w or ni2 == -1 or nj2 == -1:
                continue
            if S[ni1][nj1] == S[ni2][nj2]:
                tmp = (ni1, nj1, ni2, nj2)
                ndp[tmp] = ndp.get(tmp, 0) + v
                ndp[tmp] %= MOD
    dp = ndp

ans = 0
for (i1, j1, i2, j2), v in dp.items():
    if abs(i1 - i2) + abs(j1 - j2) <= 1:
        ans += v
        ans %= MOD
print(ans)

0