結果

問題 No.1916 Making Palindrome on Gird
ユーザー ruthenruthen
提出日時 2022-04-29 22:41:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 684 ms / 3,000 ms
コード長 1,828 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 210,444 KB
実行使用メモリ 133,104 KB
最終ジャッジ日時 2023-09-11 14:03:57
合計ジャッジ時間 9,158 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,512 KB
testcase_01 AC 3 ms
5,244 KB
testcase_02 AC 3 ms
5,400 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 3 ms
5,308 KB
testcase_05 AC 3 ms
5,372 KB
testcase_06 AC 3 ms
5,248 KB
testcase_07 AC 3 ms
5,240 KB
testcase_08 AC 3 ms
5,504 KB
testcase_09 AC 3 ms
5,256 KB
testcase_10 AC 3 ms
5,320 KB
testcase_11 AC 3 ms
5,304 KB
testcase_12 AC 3 ms
5,240 KB
testcase_13 AC 3 ms
5,400 KB
testcase_14 AC 3 ms
5,408 KB
testcase_15 AC 56 ms
14,892 KB
testcase_16 AC 45 ms
12,892 KB
testcase_17 AC 109 ms
24,272 KB
testcase_18 AC 329 ms
59,188 KB
testcase_19 AC 318 ms
57,432 KB
testcase_20 AC 317 ms
57,412 KB
testcase_21 AC 324 ms
58,408 KB
testcase_22 AC 325 ms
58,664 KB
testcase_23 AC 3 ms
5,296 KB
testcase_24 AC 3 ms
5,424 KB
testcase_25 AC 3 ms
5,368 KB
testcase_26 AC 3 ms
5,300 KB
testcase_27 AC 4 ms
5,292 KB
testcase_28 AC 680 ms
133,072 KB
testcase_29 AC 679 ms
133,032 KB
testcase_30 AC 684 ms
133,084 KB
testcase_31 AC 684 ms
133,076 KB
testcase_32 AC 680 ms
133,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
ostream &operator<<(ostream &os, const mint &p) { return os << p.val(); }

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;
            // show(i, j, dp[i][j]);
            // dp[i][j] -> dp[i+1][j] or dp[i][j+1]
            for (auto [k, val] : dp[i][j]) {
                auto [cx, cy] = finv(k);
                if (abs(i - cx) + abs(j - cy) <= 1) {
                    ans += val;
                    // show(ans);
                    continue;
                }
                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;
                    }
                }
            }
        }
    }
    cout << ans.val() << '\n';
    return 0;
}
0