結果

問題 No.3429 Palindromic Path (Hard)
コンテスト
ユーザー shingo0909
提出日時 2026-01-11 14:25:43
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 901 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,357 ms
コンパイル使用メモリ 351,924 KB
実行使用メモリ 87,552 KB
最終ジャッジ日時 2026-01-11 14:25:49
合計ジャッジ時間 6,322 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
    function<mint(tuple<int,int,int,int>)>dfs=[&](tuple<int,int,int,int> in){
        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));
        ans+=dfs(make_tuple(x,y+1,a-1,b));
        ans+=dfs(make_tuple(x+1,y,a,b-1));
        ans+=dfs(make_tuple(x,y+1,a,b-1));
        return memo[in]=ans;
    };
    cout <<  dfs(make_tuple(0,0,n-1,n-1)).val() << endl;
}
0