結果
| 問題 | No.3429 Palindromic Path (Hard) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 14:29:21 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 899 bytes |
| 記録 | |
| コンパイル時間 | 3,554 ms |
| コンパイル使用メモリ | 351,388 KB |
| 実行使用メモリ | 87,552 KB |
| 最終ジャッジ日時 | 2026-01-11 14:29:28 |
| 合計ジャッジ時間 | 6,690 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using mint = atcoder::modint998244353;
int main(){
int n;
cin >> n;
vector<string>s(n);
rep(i,n)cin >> s[i];
map<tuple<int,int,int,int>,mint>memo;
auto dfs=[&](tuple<int,int,int,int> in, auto &dfs){
auto [x,y,a,b]=in;
if(x+y == a+b){
return mint(x==a?1:0);
}
if(x>a || y>b)return mint(0);
if(s[x][y]!=s[a][b])return mint(0);
if(memo.count(in))return memo[in];
mint ans=0;
ans+=dfs(make_tuple(x+1,y,a-1,b),dfs);
ans+=dfs(make_tuple(x,y+1,a-1,b),dfs);
ans+=dfs(make_tuple(x+1,y,a,b-1),dfs);
ans+=dfs(make_tuple(x,y+1,a,b-1),dfs);
return memo[in]=ans;
};
cout << dfs(make_tuple(0,0,n-1,n-1),dfs).val() << endl;
}