結果

問題 No.1916 Making Palindrome on Gird
ユーザー i_am_noobi_am_noob
提出日時 2023-02-11 04:07:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 3,000 ms
コード長 1,380 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 199,820 KB
実行使用メモリ 34,512 KB
最終ジャッジ日時 2023-09-22 03:43:46
合計ジャッジ時間 5,100 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 29 ms
12,532 KB
testcase_14 AC 19 ms
9,900 KB
testcase_15 AC 36 ms
13,764 KB
testcase_16 AC 27 ms
12,036 KB
testcase_17 AC 61 ms
18,956 KB
testcase_18 AC 79 ms
20,312 KB
testcase_19 AC 79 ms
20,304 KB
testcase_20 AC 80 ms
20,264 KB
testcase_21 AC 80 ms
20,320 KB
testcase_22 AC 79 ms
20,268 KB
testcase_23 AC 17 ms
34,512 KB
testcase_24 AC 17 ms
33,328 KB
testcase_25 AC 16 ms
34,260 KB
testcase_26 AC 16 ms
34,264 KB
testcase_27 AC 16 ms
34,336 KB
testcase_28 AC 103 ms
20,380 KB
testcase_29 AC 103 ms
20,260 KB
testcase_30 AC 102 ms
20,320 KB
testcase_31 AC 103 ms
20,568 KB
testcase_32 AC 104 ms
20,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int maxn=205,mod=1000000007;
int add(int& x, int y){x+=y; if(x>=mod) x-=mod; return x;}
int n,m,dp[maxn][maxn][maxn];
char a[maxn][maxn],b[maxn][maxn];
bool valid(int x, int y){return x>=0&&x<n&&y>=0&&y<m;}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m; int k=(n+m)/2;
    for(int i=0; i<n; ++i) for(int j=0; j<m; ++j) cin >> a[i][j],b[n-1-i][m-1-j]=a[i][j];
    dp[0][0][0]=1;
    for(int i=0; i<k-1; ++i){
        for(int j1=0; j1<=i; ++j1) for(int j2=0; j2<=i; ++j2) if(valid(j1,i-j1)&&valid(j2,i-j2)){
            if(a[j1][i-j1]!=b[j2][i-j2]){
                dp[i][j1][j2]=0;
                continue;
            }
            for(auto t1: {0,1}) for(auto t2: {0,1}){
                int x1=j1+t1,y1=i+1-x1,x2=j2+t2,y2=i+1-x2;
                if(valid(x1,y1)&&valid(x2,y2)&&a[x1][y1]==b[x2][y2]) add(dp[i+1][j1+t1][j2+t2],dp[i][j1][j2]);
            }
        }
    }
    int res=0;
    for(int j1=0; j1<k; ++j1) for(int j2=0; j2<k; ++j2) if(valid(j1,k-1-j1)&&valid(j2,k-1-j2)&&a[j1][k-1-j1]==b[j2][k-1-j2]){
        int x1=j1,y1=k-1-j1,x2=n-1-j2,y2=m-1-(k-1-j2);
        if(abs(x1-x2)+abs(y1-y2)<=1) add(res,dp[k-1][j1][j2]);
    }
    cout << res << "\n";
}
0