結果
| 問題 | No.3429 Palindromic Path (Hard) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 14:31:18 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,613 bytes |
| 記録 | |
| コンパイル時間 | 6,687 ms |
| コンパイル使用メモリ | 386,320 KB |
| 実行使用メモリ | 223,564 KB |
| 最終ジャッジ日時 | 2026-01-11 14:31:28 |
| 合計ジャッジ時間 | 10,074 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 3 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define inr(l, x, r) (l <= x && x < r)
#define ll long long
#define ld long double
// using mint = modint1000000007;
using mint = modint998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main(){
int n; cin >> n;
vector<string> s(n);
rep(i, 0, n) cin >> s[i];
unordered_map<ll, mint> memo;
auto id = [&](int u, int l, int d, int r) -> ll {
ll res = 0;
res += (ll)u<<30;
res += (ll)l<<20;
res += (ll)d<<10;
res += (ll)r;
return res;
};
auto f = [&](auto self, int u, int l, int d, int r) -> mint {
if(memo.count(id(u, d, l, r))) return memo[id(u, d, l, r)];
if(u == d && l == r) return 1;
if(s[u][l] != s[d][r]) return 0;
mint res = 0;
if(inr(0, l+1, n) && inr(0, r-1, n)) res += self(self, u, l+1, d, r-1);
if(inr(0, l+1, n) && inr(0, d-1, n)) res += self(self, u, l+1, d-1, r);
if(inr(0, u+1, n) && inr(0, r-1, n)) res += self(self, u+1, l, d, r-1);
if(inr(0, u+1, n) && inr(0, d-1, n)) res += self(self, u+1, l, d-1, r);
return memo[id(u, d, l, r)] = res;
};
cout << f(f, 0, 0, n-1, n-1).val() << endl;
return 0;
}