No.3428 Palindromic Path (Easy)
*This problem is Palindromic Path (Hard) with different constraints.
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
まみめ
kidodesu