結果
| 問題 | No.3429 Palindromic Path (Hard) |
| コンテスト | |
| ユーザー |
のびるくん
|
| 提出日時 | 2026-01-11 15:55:12 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 910 bytes |
| 記録 | |
| コンパイル時間 | 1,210 ms |
| コンパイル使用メモリ | 112,136 KB |
| 実行使用メモリ | 16,216 KB |
| 最終ジャッジ日時 | 2026-01-11 15:55:18 |
| 合計ジャッジ時間 | 4,927 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 3 |
ソースコード
#include<algorithm>
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<vector<char>> c(N, vector<char>(N));
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> c[i][j];
vector<map<string, int>> S(N);
auto DFS1 = [&](auto dfs, int x, int y, string s) -> void{
if (x + y == N - 1) {
S[x][s]++;
return;
}
if (x + 1 != N)
dfs(dfs, x + 1, y, s + c[x][y]);
if (y + 1 != N)
dfs(dfs, x, y + 1, s + c[x][y]);
};
DFS1(DFS1, 0, 0, "");
ll ans = 0;
const ll MOD = 998244353;
auto DFS2 = [&](auto dfs, int x, int y, string s) {
if (x + y == N - 1) {
ans += S[x][s];
ans %= MOD;
return;
}
if (x != 0)
dfs(dfs, x - 1, y, s + c[x][y]);
if (y != 0)
dfs(dfs, x, y - 1, s + c[x][y]);
};
DFS2(DFS2, N - 1, N - 1, "");
cout << ans << endl;
return 0;
}
のびるくん