結果
| 問題 | No.3429 Palindromic Path (Hard) |
| コンテスト | |
| ユーザー |
koheijkt
|
| 提出日時 | 2026-01-11 16:53:06 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,220 bytes |
| 記録 | |
| コンパイル時間 | 330 ms |
| コンパイル使用メモリ | 82,212 KB |
| 実行使用メモリ | 848,476 KB |
| 最終ジャッジ日時 | 2026-01-11 16:53:12 |
| 合計ジャッジ時間 | 2,892 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 MLE * 1 -- * 3 |
ソースコード
import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 1e18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
def I(): return sys.stdin.readline().rstrip()
def II(): return int(sys.stdin.readline().rstrip())
def IS(): return sys.stdin.readline().rstrip().split()
def MII(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(sys.stdin.readline().rstrip())
def TII(): return tuple(map(int, sys.stdin.readline().rstrip().split()))
def LII(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LSI(): return list(map(str, sys.stdin.readline().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b
def chmax(DP,i,v):
if DP[i] < v: DP[i] = v
def chmin(DP,i,v):
if DP[i] > v: DP[i] = v
# 座標 → 通し番号
# num = i * W + j
#def givenum(i, j, W):
# return i * W + j
# 通し番号 → 座標
# i, j = divmod(num, W)
N = II()
def check(i, j):
return 0 <= i < N and 0 <= j < N
C = [LI() for _ in range(N)]
que = deque()
DP = [[0] * (N*N) for _ in range(N*N)]
for i in range(N):
j = N - 1 - i
num = i*N + j
DP[num][num] = 1
que.append((num, num))
done = set()
while que:
lnum, rnum = que.popleft()
if (lnum, rnum) in done:
continue
done.add((lnum, rnum))
li, lj = divmod(lnum, N)
ri, rj = divmod(rnum, N)
for ii, jj in [(0, -1),(-1, 0)]:
lni, lnj = li+ii, lj+jj
lnexnum = lni*N + lnj
if not check(lni, lnj):
continue
# この lni, lnj に対して
for ii, jj in [(0, 1),(1, 0)]:
rni, rnj = ri+ii, rj+jj
rnexnum = rni*N + rnj
if not check(rni, rnj):
continue
# (lni, lnj) * (rni, rnj) のペア
if C[lni][lnj] == C[rni][rnj]:
DP[lnexnum][rnexnum] += DP[lnum][rnum] % MOD
que.append((lnexnum, rnexnum))
ans = DP[0][-1] % MOD
print(ans)
koheijkt