結果

問題 No.1916 Making Palindrome on Gird
ユーザー 👑 kmjpkmjp
提出日時 2022-04-29 22:19:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 382 ms / 3,000 ms
コード長 1,707 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 205,400 KB
実行使用メモリ 36,016 KB
最終ジャッジ日時 2023-09-11 13:38:20
合計ジャッジ時間 8,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 158 ms
20,724 KB
testcase_14 AC 97 ms
15,564 KB
testcase_15 AC 190 ms
22,968 KB
testcase_16 AC 133 ms
19,748 KB
testcase_17 AC 350 ms
33,228 KB
testcase_18 AC 381 ms
35,784 KB
testcase_19 AC 382 ms
35,856 KB
testcase_20 AC 380 ms
35,868 KB
testcase_21 AC 381 ms
35,836 KB
testcase_22 AC 379 ms
35,792 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 369 ms
36,016 KB
testcase_29 AC 369 ms
35,796 KB
testcase_30 AC 367 ms
35,920 KB
testcase_31 AC 370 ms
35,792 KB
testcase_32 AC 368 ms
35,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W;
string S[202];

const ll mo=1000000007;
ll dp[202][202][202];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	
	if(S[0][0]!=S[H-1][W-1]) {
		cout<<0<<endl;
		return;
	}
	
	int y1,y2;
	dp[0][0][H-1]=1;
	FOR(i,(H+W-2)/2) {
		FOR(y1,H) FOR(y2,H) {
			int x1=i-y1;
			if(x1<0||x1>=W) continue;
			int x2=(H+W-2-i)-y2;
			if(x2<0||x2>=W) continue;
			
			vector<pair<int,int>> C1,C2;
			if(y1<H-1) C1.push_back({S[y1+1][x1],y1+1});
			if(x1<W-1) C1.push_back({S[y1][x1+1],y1});
			if(y2>0) C2.push_back({S[y2-1][x2],y2-1});
			if(x2>0) C2.push_back({S[y2][x2-1],y2});
			FORR2(c1,yy1,C1) FORR2(c2,yy2,C2) {
				if(c1==c2) (dp[i+1][yy1][yy2]+=dp[i][y1][y2])%=mo;
			}
		}
	}
	
	ll ret=0;
	FOR(y1,H) FOR(y2,H) {
		if((H+W)%2==0) {
			if(y1==y2) ret+=dp[(H+W-2)/2][y1][y2];
		}
		else {
			if(y1==y2||y1+1==y2) ret+=dp[(H+W-2)/2][y1][y2];
		}
	}
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0