結果
| 問題 | No.1916 Making Palindrome on Gird |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-29 22:29:52 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,625 bytes |
| 記録 | |
| コンパイル時間 | 2,455 ms |
| コンパイル使用メモリ | 205,256 KB |
| 最終ジャッジ日時 | 2025-01-28 23:15:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
#include <atcoder/modint>
using mint = atcoder::modint1000000007;
map<int, mint> dp[200][200];
int f(int x, int y) { return x * 200 + y; }
pair<int, int> finv(int k) { return {k / 200, k % 200}; }
const int dx[2] = {0, 1}, dy[2] = {1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, W;
cin >> H >> W;
V<string> S(H);
rep(i, H) cin >> S[i];
dp[0][0][f(H - 1, W - 1)] = 1;
mint ans = 0;
for (int k = 0; k < (H + W) / 2; k++) {
for (int i = 0; i < H; i++) {
int j = k - i;
if (!(0 <= j && j < W)) continue;
// dp[i][j] -> dp[i+1][j] or dp[i][j+1]
for (auto [k, val] : dp[i][j]) {
auto [cx, cy] = finv(k);
rep(a, 2) {
rep(b, 2) {
int nx = i + dx[a], ny = j + dy[a];
int ncx = cx - dx[b], ncy = cy - dy[b];
if (!(0 <= nx && nx < H && 0 <= ny && ny < W)) continue;
if (!(0 <= ncx && ncx < H && 0 <= ncy && ncy < W)) continue;
if (S[nx][ny] != S[ncx][ncy]) continue;
dp[nx][ny][f(ncx, ncy)] += val;
if (abs(nx - ncx) + abs(ny - ncy) <= 1) ans += val;
}
}
}
}
}
cout << ans.val() << '\n';
return 0;
}