結果

問題 No.1916 Making Palindrome on Gird
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 21:36:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,137 ms / 3,000 ms
コード長 1,201 bytes
コンパイル時間 1,076 ms
コンパイル使用メモリ 95,124 KB
実行使用メモリ 87,564 KB
最終ジャッジ日時 2023-09-11 12:30:57
合計ジャッジ時間 16,729 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 98 ms
10,904 KB
testcase_16 AC 55 ms
8,068 KB
testcase_17 AC 210 ms
18,132 KB
testcase_18 AC 706 ms
41,556 KB
testcase_19 AC 669 ms
39,940 KB
testcase_20 AC 681 ms
40,800 KB
testcase_21 AC 688 ms
41,256 KB
testcase_22 AC 685 ms
40,852 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2,123 ms
87,412 KB
testcase_29 AC 2,137 ms
87,360 KB
testcase_30 AC 2,115 ms
87,564 KB
testcase_31 AC 2,133 ms
87,372 KB
testcase_32 AC 2,098 ms
87,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using m32 = atcoder::static_modint<1000000007>;

int H,W;
map<pair<pair<int,int>, pair<int,int>>, m32> dp;
vector<string> S;

m32 recursion(int y1, int x1, int y2, int x2){
    if(y1 > y2 || x1 > x2){ return m32::raw(0); }
    if(S[y1][x1] != S[y2][x2]) return m32::raw(0);
    if(y1 + x1 + 1 >= x2 + y2) return m32::raw(1);
    if(dp.count({{y1,x1},{y2,x2}})) return dp[{{y1,x1},{y2,x2}}];
    m32 ans = 0;
    ans += recursion(y1+1, x1, y2-1, x2);
    ans += recursion(y1+1, x1, y2, x2-1);
    ans += recursion(y1, x1+1, y2-1, x2);
    ans += recursion(y1, x1+1, y2, x2-1);
    return dp[{{y1,x1},{y2,x2}}] = ans;
}

int main(){
    cin >> H >> W;
    S.resize(H);
    rep(y,H) cin >> S[y];
    m32 ans = recursion(0,0,H-1,W-1);
    cout << ans.val() << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0