結果

問題 No.1916 Making Palindrome on Gird
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-29 22:59:42
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,775 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 177,228 KB
最終ジャッジ日時 2023-09-11 14:25:09
合計ジャッジ時間 15,404 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,572 KB
testcase_01 AC 86 ms
71,620 KB
testcase_02 AC 114 ms
77,412 KB
testcase_03 AC 87 ms
71,564 KB
testcase_04 AC 87 ms
71,424 KB
testcase_05 AC 87 ms
71,472 KB
testcase_06 AC 90 ms
71,600 KB
testcase_07 AC 87 ms
71,276 KB
testcase_08 AC 90 ms
71,580 KB
testcase_09 RE -
testcase_10 WA -
testcase_11 AC 90 ms
72,316 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 119 ms
77,892 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 AC 293 ms
80,780 KB
testcase_18 AC 681 ms
103,480 KB
testcase_19 AC 641 ms
102,876 KB
testcase_20 AC 657 ms
102,264 KB
testcase_21 AC 678 ms
101,968 KB
testcase_22 AC 653 ms
102,804 KB
testcase_23 AC 97 ms
77,288 KB
testcase_24 AC 97 ms
77,344 KB
testcase_25 AC 97 ms
77,172 KB
testcase_26 AC 99 ms
77,324 KB
testcase_27 AC 94 ms
77,112 KB
testcase_28 AC 1,540 ms
175,360 KB
testcase_29 AC 1,546 ms
177,228 KB
testcase_30 AC 1,544 ms
175,872 KB
testcase_31 AC 1,486 ms
176,572 KB
testcase_32 AC 1,538 ms
175,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


H, W = map(int, input().split())
K = H + W - 1
gap = 0
if (H + W - 1) % 2 == 0:
    W += 1
    gap = 1
G = [[26] * W for _ in range(H)]

for i in range(H):
    S = input()
    for j, s in enumerate(S):
        if (i + j) * 2 >= K:
            j += gap
        G[i][j] = ord(s) - 97


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:
    update = False
    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 (nx, ny) != (nnx, nny):
                        continue
                ndp[id(nx, ny, nnx, nny)] += v
                ndp[id(nx, ny, nnx, nny)] %= mod
                update = True
    dp = ndp
    if finish:
        break
    if not update:
        break

if not finish:
    print(0)
else:
    ans = 0
    for v in dp.values():
        ans += v
        ans %= mod
    print(ans)
0