結果

問題 No.1916 Making Palindrome on Gird
ユーザー rlangevinrlangevin
提出日時 2023-10-10 00:06:04
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,034 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 272,984 KB
最終ジャッジ日時 2023-10-10 00:06:18
合計ジャッジ時間 11,713 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,936 KB
testcase_01 AC 100 ms
71,268 KB
testcase_02 AC 138 ms
78,428 KB
testcase_03 AC 101 ms
71,320 KB
testcase_04 AC 107 ms
76,244 KB
testcase_05 AC 104 ms
76,252 KB
testcase_06 RE -
testcase_07 AC 105 ms
76,244 KB
testcase_08 AC 105 ms
76,184 KB
testcase_09 RE -
testcase_10 AC 101 ms
71,728 KB
testcase_11 RE -
testcase_12 AC 105 ms
76,160 KB
testcase_13 AC 141 ms
79,644 KB
testcase_14 AC 131 ms
78,124 KB
testcase_15 AC 823 ms
181,184 KB
testcase_16 RE -
testcase_17 AC 1,711 ms
272,984 KB
testcase_18 TLE -
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 #

H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
    
from collections import *
Q = deque()
if S[0][0] != S[-1][-1]:
    print(0)
    exit()
    
mod = 10**9 + 7
Q.append((0, 0, H - 1, W - 1))
D = defaultdict(int)
D[(0, 0, H - 1, W - 1)] = 1
dx = [1, 0]
dy = [0, 1]
ans = 0
SS = set()
seen = set()
while Q:
    t = Q.popleft()
    sx, sy, gx, gy = t
    if gx + gy <= sx + sy + 1:
        if abs(sx - gx) + abs(sy - gy) <= 1 and t not in SS:
            SS.add(t)
            ans += D[(sx, sy, gx, gy)]
            ans %= mod
        continue
    
    for a in range(2):
        for b in range(2):
            nsx = sx + dx[a]
            nsy = sy + dy[a]
            ngx = gx - dx[b]
            ngy = gy - dy[b]
            if S[nsx][nsy] != S[ngx][ngy]:
                continue
            nt = (nsx, nsy, ngx, ngy)
            D[nt] += D[t]
            D[nt] %= mod
            if nt in seen:
                continue
            seen.add(nt)
            Q.append(nt)
            
print(ans)
0