結果
| 問題 | No.3428 Palindromic Path (Easy) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-11 13:52:53 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,258 bytes |
| 記録 | |
| コンパイル時間 | 2,038 ms |
| コンパイル使用メモリ | 227,472 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-11 13:53:13 |
| 合計ジャッジ時間 | 2,736 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint.hpp>
using namespace std;
using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using f64 = double;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(18);
_main();
}
void _main() {
i64 n;
cin >> n;
vector<string> s(n);
for (i64 i = 0; i < n; i++) cin >> s[i];
map<pair<p2, p2>, mint> mp;
for (i64 i = 0; i < n; i++) mp[{{i, n - i - 1}, {i, n - i - 1}}] = 1;
i64 nxt[5] = {0, -1, 0, 1, 0};
for (i64 k = n - 1; k >= 1; k--) {
map<pair<p2, p2>, mint> nmp;
for (auto [pp, c] : mp) {
auto [a, b] = pp;
auto [i1, j1] = a;
auto [i2, j2] = b;
for (i64 x = 0; x < 2; x++) for (i64 y = 2; y < 4; y++) {
i64 ni1 = i1 + nxt[x], nj1 = j1 + nxt[x + 1];
i64 ni2 = i2 + nxt[y], nj2 = j2 + nxt[y + 1];
if (ni1 < 0 || nj1 < 0 || ni2 >= n || nj2 >= n) continue;
if (s[ni1][nj1] != s[ni2][nj2]) continue;
nmp[{{ni1, nj1}, {ni2, nj2}}] += c;
}
}
swap(mp, nmp);
}
mint ans = 0;
for (auto [pp, c] : mp) {
ans += c;
}
cout << ans.val() << "\n";
}