問題一覧 > 通常問題

No.3428 Palindromic Path (Easy)

レベル : / AI推定難易度 : 189 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 79
作問者 : まみめ / テスター : harel hirayuu_yc syndrome kidodesu 👑 ArcAki 👑 qand rogi52 Eku
お気に入りにしたユーザー ProblemId : 12967 / 自分の提出
問題文最終更新日: 2026-01-12 12:56:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest YNUCPC Contest 2 (順位表) の他の問題:

*This problem is Palindromic Path (Hard) with different constraints.

(This problem was created by Eku.)

Problem Statement

There is a grid of $N×N$ cells. Each cell $(i,j)\space (1 \leq i,j \leq N)$ has a lowercase English letter $c_{i,j}$ written on it.
Starting from the top-left cell $(1,1)$, you move to the goal at the bottom-right cell $(N,N)$ by repeatedly moving only right or down.
Let $S$ be the string obtained by reading, in order, the characters written on the $2N-1$ cells passed through (including the start and the goal).
Among the paths from cell $(1,1)$ to $(N,N)$, how many are there for which the string $S$ is a palindrome?
Here, a string $T$ of length $M$ is a palindrome if, for every $1 \leq i \leq M$, the $i$-th character and the $(M+1-i)$-th character of $T$ are equal.
Since the answer can be very large, output it modulo $998244353$.

Input

  • $2 \leq N \leq 10$
  • $c_{i,j}$ is a lowercase English letter
$N$
$c_{1,1}c_{1,2}...c_{1,N}$
$c_{2,1}c_{2,2}...c_{2,N}$
$\vdots$
$c_{N,1}c_{N,2}...c_{N,N}$

Output

Output the total number of paths that form a palindrome, modulo $998244353$.

Sample

Sample 1
Input
3
aba
aba
aba
Output
2

Since $N=3$, there are $6$ ways to move from $(1,1)$ to $(3,3)$.

$(1,1)→(1,2)→(1,3)→(2,3)→(3,3)$ : abaaa (not a palindrome)
$(1,1)→(1,2)→(2,2)→(2,3)→(3,3)$ : abbaa (not a palindrome)
$(1,1)→(1,2)→(2,2)→(3,2)→(3,3)$ : abbba (palindrome)
$(1,1)→(2,1)→(2,2)→(2,3)→(3,3)$ : aabaa (palindrome)
$(1,1)→(2,1)→(2,2)→(3,2)→(3,3)$ : aabba (not a palindrome)
$(1,1)→(2,1)→(3,1)→(3,2)→(3,3)$ : aaaba (not a palindrome)

There are $2$ paths that form a palindrome.

Sample 2
Input
3
ynu
cpc
con
Output
0

$S$ is not a palindrome for any path, so output $0$.

Sample 3
Input
10
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
Output
48620

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。