結果

問題 No.1916 Making Palindrome on Gird
ユーザー kwm_tkwm_t
提出日時 2022-04-30 01:50:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 947 ms / 3,000 ms
コード長 2,226 bytes
コンパイル時間 4,553 ms
コンパイル使用メモリ 270,080 KB
実行使用メモリ 87,640 KB
最終ジャッジ日時 2023-09-11 17:47:57
合計ジャッジ時間 18,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,388 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 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 228 ms
35,476 KB
testcase_14 AC 131 ms
22,736 KB
testcase_15 AC 322 ms
42,776 KB
testcase_16 AC 214 ms
30,088 KB
testcase_17 AC 628 ms
77,712 KB
testcase_18 AC 794 ms
87,436 KB
testcase_19 AC 801 ms
87,580 KB
testcase_20 AC 792 ms
87,432 KB
testcase_21 AC 843 ms
87,460 KB
testcase_22 AC 809 ms
87,460 KB
testcase_23 AC 403 ms
86,164 KB
testcase_24 AC 392 ms
86,320 KB
testcase_25 AC 371 ms
86,204 KB
testcase_26 AC 399 ms
87,640 KB
testcase_27 AC 392 ms
86,832 KB
testcase_28 AC 937 ms
87,440 KB
testcase_29 AC 930 ms
87,580 KB
testcase_30 AC 937 ms
87,476 KB
testcase_31 AC 947 ms
87,460 KB
testcase_32 AC 926 ms
87,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
const int dx0[] = { -1,0 };
const int dy0[] = { 0,-1 };
const int dx1[] = { 1,0 };
const int dy1[] = { 0,1 };
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w; cin >> h >> w;
	map<pair<P, P>, mint>dp;
	vector<string>s(h);
	rep(i, h)cin >> s[i];
	rrep(i, h) {
		rrep(j, w) {
			rep(k, h) {
				int l = h - 1 + w - 1 - i - j - k;
				if (k < i)continue;
				if (l < j)continue;
				if ((k < 0) || (h <= k))continue;
				if ((l < 0) || (w <= l))continue;

				if ((1 >= k - i) && (1 >= l - j) && (1 >= (k + l - i - j))) {
					if (s[i][j] == s[k][l]) {
						dp[{ {i, j}, { k,l }}] = 1;
					}
				}
				mint val = dp[{ {i, j}, { k,l }}];
				rep(m, 2)rep(n, 2) {
					int ni = i + dx0[m];
					int nj = j + dy0[m];
					int nk = k + dx1[n];
					int nl = l + dy1[n];
					if ((ni < 0) || (h <= ni))continue;
					if ((nj < 0) || (w <= nj))continue;
					if ((nk < 0) || (h <= nk))continue;
					if ((nl < 0) || (w <= nl))continue;
					if (s[ni][nj] != s[nk][nl])continue;
					dp[{ {ni, nj}, { nk,nl }}] += val;
					//cout << i << j << k << l << endl;
					//cout << ni << nj << nk << nl << endl;
				}
			}
		}
	}
	/*for (auto[k, v] : dp) {
		cout << k.first.first << " " << k.first.second << endl;
		cout << k.second.first << " " << k.second.second << endl;
		cout << v.val() << endl;
	}*/
	mint ans = dp[{ {0, 0}, { h - 1,w - 1 }}];
	cout << ans.val() << endl;
	return 0;
}
0