結果
| 問題 |
No.1916 Making Palindrome on Gird
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2022-04-30 01:50:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 971 ms / 3,000 ms |
| コード長 | 2,226 bytes |
| コンパイル時間 | 4,226 ms |
| コンパイル使用メモリ | 260,048 KB |
| 最終ジャッジ日時 | 2025-01-29 00:45:44 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 };
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;
}
kwm_t