結果

問題 No.1916 Making Palindrome on Gird
ユーザー kwm_tkwm_t
提出日時 2022-04-30 01:53:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 3,000 ms
コード長 1,875 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 261,764 KB
実行使用メモリ 34,964 KB
最終ジャッジ日時 2023-09-11 17:51:33
合計ジャッジ時間 7,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,648 KB
testcase_01 AC 11 ms
34,948 KB
testcase_02 AC 11 ms
34,660 KB
testcase_03 AC 11 ms
34,724 KB
testcase_04 AC 11 ms
34,808 KB
testcase_05 AC 11 ms
34,736 KB
testcase_06 AC 11 ms
34,680 KB
testcase_07 AC 11 ms
34,728 KB
testcase_08 AC 11 ms
34,736 KB
testcase_09 AC 11 ms
34,676 KB
testcase_10 AC 11 ms
34,664 KB
testcase_11 AC 11 ms
34,728 KB
testcase_12 AC 11 ms
34,872 KB
testcase_13 AC 34 ms
34,780 KB
testcase_14 AC 25 ms
34,776 KB
testcase_15 AC 39 ms
34,692 KB
testcase_16 AC 30 ms
34,776 KB
testcase_17 AC 62 ms
34,704 KB
testcase_18 AC 66 ms
34,704 KB
testcase_19 AC 65 ms
34,704 KB
testcase_20 AC 65 ms
34,740 KB
testcase_21 AC 65 ms
34,824 KB
testcase_22 AC 66 ms
34,780 KB
testcase_23 AC 53 ms
34,716 KB
testcase_24 AC 53 ms
34,824 KB
testcase_25 AC 52 ms
34,964 KB
testcase_26 AC 53 ms
34,728 KB
testcase_27 AC 53 ms
34,708 KB
testcase_28 AC 63 ms
34,724 KB
testcase_29 AC 62 ms
34,868 KB
testcase_30 AC 63 ms
34,728 KB
testcase_31 AC 63 ms
34,788 KB
testcase_32 AC 63 ms
34,708 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 };
mint dp[200][200][200];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w; cin >> h >> w;
	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] = 1;
					}
				}
				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] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[0][0][h - 1].val() << endl;
	return 0;
}
0