結果
| 問題 | No.3429 Palindromic Path (Hard) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 14:26:56 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 954 bytes |
| 記録 | |
| コンパイル時間 | 3,528 ms |
| コンパイル使用メモリ | 344,752 KB |
| 実行使用メモリ | 813,824 KB |
| 最終ジャッジ日時 | 2026-01-11 14:27:02 |
| 合計ジャッジ時間 | 6,102 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 MLE * 1 -- * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#include <atcoder/modint>
using mint=atcoder::modint998244353;
int main(){
int n;
cin>>n;
vector<string> s(n);
for(int i=0;i<n;i++)cin>>s[i];
if(s[0][0]!=s[n-1][n-1]){
cout<<0<<endl;
return 0;
}
vector<vector<mint>> dp(n*n,vector<mint>(n*n));
dp[0][n*n-1]=1;
for(int i=0;i<n-1;i++){
for(int j=0;j<=i;j++){
for(int k=0;k<=i;k++){
int x1=j,y1=i-j,x2=n-k-1,y2=n-(i-k)-1;
if(s[x1+1][y1]==s[x2-1][y2]){
dp[(x1+1)*n+y1][(x2-1)*n+y2]+=dp[x1*n+y1][x2*n+y2];
}
if(s[x1][y1+1]==s[x2-1][y2]){
dp[x1*n+y1+1][(x2-1)*n+y2]+=dp[x1*n+y1][x2*n+y2];
}
if(s[x1+1][y1]==s[x2][y2-1]){
dp[(x1+1)*n+y1][(x2)*n+y2-1]+=dp[x1*n+y1][x2*n+y2];
}
if(s[x1][y1+1]==s[x2][y2-1]){
dp[(x1)*n+y1+1][(x2)*n+y2-1]+=dp[x1*n+y1][x2*n+y2];
}
}
}
}
mint ans=0;
for(int i=0;i<n;i++)ans+=dp[i*n+(n-1-i)][i*n+(n-1-i)];
cout<<ans.val()<<endl;
}