結果

問題 No.1916 Making Palindrome on Gird
ユーザー 👑 colognecologne
提出日時 2022-05-01 13:05:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 3,000 ms
コード長 1,342 bytes
コンパイル時間 3,404 ms
コンパイル使用メモリ 257,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 05:13:10
合計ジャッジ時間 6,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 33 ms
4,376 KB
testcase_18 AC 58 ms
4,376 KB
testcase_19 AC 57 ms
4,376 KB
testcase_20 AC 57 ms
4,376 KB
testcase_21 AC 57 ms
4,380 KB
testcase_22 AC 58 ms
4,376 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 23 ms
4,376 KB
testcase_26 AC 24 ms
4,380 KB
testcase_27 AC 23 ms
4,380 KB
testcase_28 AC 98 ms
4,376 KB
testcase_29 AC 97 ms
4,376 KB
testcase_30 AC 98 ms
4,376 KB
testcase_31 AC 99 ms
4,380 KB
testcase_32 AC 98 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;

using Mint = atcoder::modint1000000007;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> V(H);
    for (auto &x : V)
        cin >> x;

    vector<vector<Mint>> D(H, vector<Mint>(H));
    D[0][H - 1] = V[0][0] == V[H-1][W-1];

    for (int s = 0; s < (H + W - 2)/2; s++)
    {
        vector<vector<Mint>> E(H, vector<Mint>(H));
        for (int i = 0; i < H; i++)
            for (int j = 0; j < H; j++)
                if (D[i][j].val())
                {
                    int ux = i, uy = s - i, vx = j, vy = (H + W - 2 - s) - j;
                    if(ux != H-1 && vx != 0 && V[ux+1][uy] == V[vx-1][vy])
                        E[ux+1][vx-1] += D[i][j];
                    if(ux != H-1 && vy != 0 && V[ux+1][uy] == V[vx][vy-1])
                        E[ux+1][vx] += D[i][j];
                    if(uy != W-1 && vx != 0 && V[ux][uy+1] == V[vx-1][vy])
                        E[ux][vx-1] += D[i][j];
                    if(uy != W-1 && vy != 0 && V[ux][uy+1] == V[vx][vy-1])
                        E[ux][vx] += D[i][j];
                }
        D = E;
    }
    Mint ans = 0;
    for(int i=0; i<H; i++)
        ans += D[i][i];
    if(H%2 != W%2)
        for(int i=0; i<H-1; i++)
            ans += D[i][i+1];
    cout << ans.val() << endl;
}
0