結果

問題 No.1916 Making Palindrome on Gird
ユーザー 沙耶花沙耶花
提出日時 2022-04-29 21:44:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 3,000 ms
コード長 1,338 bytes
コンパイル時間 4,944 ms
コンパイル使用メモリ 266,620 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 12:42:21
合計ジャッジ時間 7,669 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 33 ms
4,380 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 41 ms
4,380 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 79 ms
4,380 KB
testcase_18 AC 97 ms
4,376 KB
testcase_19 AC 96 ms
4,380 KB
testcase_20 AC 95 ms
4,380 KB
testcase_21 AC 96 ms
4,376 KB
testcase_22 AC 96 ms
4,380 KB
testcase_23 AC 64 ms
4,380 KB
testcase_24 AC 63 ms
4,380 KB
testcase_25 AC 63 ms
4,376 KB
testcase_26 AC 64 ms
4,376 KB
testcase_27 AC 63 ms
4,380 KB
testcase_28 AC 122 ms
4,376 KB
testcase_29 AC 121 ms
4,380 KB
testcase_30 AC 120 ms
4,376 KB
testcase_31 AC 120 ms
4,376 KB
testcase_32 AC 121 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int main(){
	
	int H,W;
	cin>>H>>W;
	
	vector<string> S(H);
	rep(i,H)cin>>S[i];
	
	vector dp(H,vector<mint>(H,0));
	if(S[0][0]==S.back().back()){
		dp[0][H-1] = 1;
	}
	vector<int> dx = {1,0},dy = {0,1};
	int len = H+W-1;
	rep(i,(len-1)/2){
		vector ndp(H,vector<mint>(H,0));
		int X = i,Y = len-1-i;
		rep(j,H){
			int x0 = j,y0 = X-j;
			if(x0>=H)continue;
			if(y0<0||y0>=W)continue;
			rep(k,H){
				int x1 = k,y1 = Y-k;
				if(x1>=H)continue;
				if(y1<0||y1>=W)continue;
				rep(l0,2){
					int x2 = x0+dx[l0],y2 = y0 + dy[l0];
					if(x2<0||x2>=H||y2<0||y2>=W)continue;
					rep(l1,2){
						int x3 = x1 - dx[l1],y3 = y1 - dy[l1];
						
						if(x3<0||x3>=H||y3<0||y3>=W)continue;
						if(S[x2][y2]!=S[x3][y3])continue;
						ndp[x2][x3] += dp[j][k];
					}
				}
			}
		}
		/*
		rep(j,dp.size()){
			rep(k,dp[i].size()){
				cout<<ndp[j][k].val()<<',';
			}
			cout<<endl;
		}
		*/
		swap(dp,ndp);
	}
	
	mint ans = 0;
	if(len%2==1){
		rep(i,dp.size()){
			ans += dp[i][i];
		}
	}
	else{
		rep(i,dp.size()){
			ans += dp[i][i];
			if(i+1!=dp.size())ans += dp[i][i+1];
		}
	}
	cout<<ans.val()<<endl;
    return 0;
}
0