結果

問題 No.1916 Making Palindrome on Gird
ユーザー 👑 rin204rin204
提出日時 2022-05-04 18:45:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 888 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 267,488 KB
最終ジャッジ日時 2023-09-16 22:58:09
合計ジャッジ時間 22,681 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,932 KB
testcase_01 AC 77 ms
71,220 KB
testcase_02 AC 108 ms
77,036 KB
testcase_03 AC 77 ms
71,424 KB
testcase_04 AC 79 ms
75,160 KB
testcase_05 AC 81 ms
75,124 KB
testcase_06 AC 80 ms
75,052 KB
testcase_07 AC 80 ms
75,120 KB
testcase_08 AC 79 ms
75,168 KB
testcase_09 AC 79 ms
74,848 KB
testcase_10 AC 76 ms
71,404 KB
testcase_11 AC 81 ms
75,060 KB
testcase_12 AC 78 ms
74,924 KB
testcase_13 AC 100 ms
76,464 KB
testcase_14 AC 99 ms
76,408 KB
testcase_15 AC 439 ms
105,008 KB
testcase_16 AC 360 ms
90,544 KB
testcase_17 AC 783 ms
135,376 KB
testcase_18 AC 2,772 ms
263,944 KB
testcase_19 AC 2,706 ms
264,072 KB
testcase_20 AC 2,705 ms
264,608 KB
testcase_21 AC 2,770 ms
264,564 KB
testcase_22 AC 2,763 ms
265,028 KB
testcase_23 AC 81 ms
71,280 KB
testcase_24 AC 81 ms
71,316 KB
testcase_25 AC 81 ms
71,476 KB
testcase_26 AC 80 ms
71,248 KB
testcase_27 AC 81 ms
71,100 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