結果

問題 No.1916 Making Palindrome on Gird
ユーザー ruthenruthen
提出日時 2022-04-29 22:29:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,625 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 210,808 KB
実行使用メモリ 133,072 KB
最終ジャッジ日時 2023-09-11 13:50:50
合計ジャッジ時間 8,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,408 KB
testcase_01 AC 3 ms
5,160 KB
testcase_02 AC 4 ms
5,444 KB
testcase_03 WA -
testcase_04 AC 3 ms
5,352 KB
testcase_05 AC 3 ms
5,164 KB
testcase_06 AC 3 ms
5,312 KB
testcase_07 AC 3 ms
5,168 KB
testcase_08 AC 3 ms
5,180 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
5,260 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 3 ms
5,256 KB
testcase_15 WA -
testcase_16 AC 43 ms
12,828 KB
testcase_17 AC 106 ms
23,924 KB
testcase_18 AC 328 ms
59,340 KB
testcase_19 AC 323 ms
57,444 KB
testcase_20 AC 319 ms
57,276 KB
testcase_21 AC 327 ms
58,272 KB
testcase_22 AC 327 ms
58,876 KB
testcase_23 AC 3 ms
5,292 KB
testcase_24 AC 3 ms
5,552 KB
testcase_25 AC 3 ms
5,212 KB
testcase_26 AC 3 ms
5,364 KB
testcase_27 AC 3 ms
5,292 KB
testcase_28 AC 667 ms
133,000 KB
testcase_29 AC 664 ms
133,072 KB
testcase_30 AC 660 ms
132,988 KB
testcase_31 AC 677 ms
133,064 KB
testcase_32 AC 666 ms
133,044 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;

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;
}
0