結果
| 問題 |
No.1916 Making Palindrome on Gird
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2022-04-30 01:53:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 3,000 ms |
| コード長 | 1,875 bytes |
| コンパイル時間 | 5,021 ms |
| コンパイル使用メモリ | 252,168 KB |
| 最終ジャッジ日時 | 2025-01-29 00:46:12 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#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;
}
kwm_t