結果

問題 No.1916 Making Palindrome on Gird
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-29 23:13:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,574 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 86,012 KB
実行使用メモリ 81,328 KB
最終ジャッジ日時 2023-09-11 14:45:03
合計ジャッジ時間 6,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
75,740 KB
testcase_01 AC 95 ms
71,212 KB
testcase_02 AC 129 ms
77,388 KB
testcase_03 AC 95 ms
71,276 KB
testcase_04 AC 95 ms
71,176 KB
testcase_05 AC 97 ms
71,184 KB
testcase_06 AC 99 ms
71,412 KB
testcase_07 AC 99 ms
71,464 KB
testcase_08 AC 98 ms
71,432 KB
testcase_09 AC 96 ms
71,304 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from collections import defaultdict
mod = 10 ** 9 + 7
U = 201


H, W = map(int, input().split())
G = [input() for _ in range(H)]


def id(x, y, xx, yy):
    res = x
    res = res * U + y
    res = res * U + xx
    res = res * U + yy
    return res


def parse(m):
    m, yy = divmod(m, U)
    m, xx = divmod(m, U)
    x, y = divmod(m, U)
    return x, y, xx, yy


if G[0][0] != G[H-1][W-1]:
    print(0)
    exit()
dp = defaultdict(int)
dp[id(0, 0, H-1, W-1)] = 1
while True:
    finish = False
    ndp = defaultdict(int)
    for k, v in dp.items():
        x, y, xx, yy = parse(k)
        for di, dj in [(0, 1), (1, 0)]:
            nx = x + di
            ny = y + dj
            if nx < 0 or nx >= H or ny < 0 or ny >= W:
                continue
            for ddi, ddj in [(0, -1), (-1, 0)]:
                nnx = xx + ddi
                nny = yy + ddj
                if nnx < 0 or nnx >= H or nny < 0 or nny >= W:
                    continue
                if G[nx][ny] != G[nnx][nny]:
                    continue
                if (nx + ny) >= (nnx + nny):
                    finish = True
                    if (H + W - 1) % 2 == 1 and (nx, ny) != (nnx, nny):
                        continue
                    if (H + W - 1) % 2 == 0 and id(x, y, xx, yy) != id(nnx, nny, nx, ny):
                        continue
                ndp[id(nx, ny, nnx, nny)] += v
                ndp[id(nx, ny, nnx, nny)] %= mod
    dp = ndp
    if finish:
        break

ans = 0
for k, v in dp.items():
    ans += v
    ans %= mod
print(ans)
0