結果
問題 | No.1916 Making Palindrome on Gird |
ユーザー | Kude |
提出日時 | 2022-04-29 21:47:15 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 105 ms / 3,000 ms |
コード長 | 1,788 bytes |
コンパイル時間 | 2,640 ms |
コンパイル使用メモリ | 226,432 KB |
実行使用メモリ | 39,860 KB |
最終ジャッジ日時 | 2023-09-11 12:46:06 |
合計ジャッジ時間 | 5,120 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
39,544 KB |
testcase_01 | AC | 13 ms
39,564 KB |
testcase_02 | AC | 13 ms
39,556 KB |
testcase_03 | AC | 12 ms
39,708 KB |
testcase_04 | AC | 12 ms
39,516 KB |
testcase_05 | AC | 13 ms
39,564 KB |
testcase_06 | AC | 11 ms
39,624 KB |
testcase_07 | AC | 12 ms
39,608 KB |
testcase_08 | AC | 13 ms
39,824 KB |
testcase_09 | AC | 12 ms
39,516 KB |
testcase_10 | AC | 13 ms
39,524 KB |
testcase_11 | AC | 13 ms
39,584 KB |
testcase_12 | AC | 13 ms
39,568 KB |
testcase_13 | AC | 51 ms
39,600 KB |
testcase_14 | AC | 36 ms
39,708 KB |
testcase_15 | AC | 59 ms
39,596 KB |
testcase_16 | AC | 44 ms
39,540 KB |
testcase_17 | AC | 101 ms
39,860 KB |
testcase_18 | AC | 105 ms
39,824 KB |
testcase_19 | AC | 105 ms
39,760 KB |
testcase_20 | AC | 105 ms
39,636 KB |
testcase_21 | AC | 105 ms
39,612 KB |
testcase_22 | AC | 105 ms
39,824 KB |
testcase_23 | AC | 12 ms
39,592 KB |
testcase_24 | AC | 12 ms
39,564 KB |
testcase_25 | AC | 12 ms
39,600 KB |
testcase_26 | AC | 12 ms
39,760 KB |
testcase_27 | AC | 12 ms
39,632 KB |
testcase_28 | AC | 100 ms
39,576 KB |
testcase_29 | AC | 101 ms
39,580 KB |
testcase_30 | AC | 101 ms
39,636 KB |
testcase_31 | AC | 100 ms
39,604 KB |
testcase_32 | AC | 101 ms
39,608 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using mint = modint1000000007; mint dp[210][210][210]; const int di[] = {1, 0, -1, 0}; const int dj[] = {0, 1, 0, -1}; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; if (s[0][0] != s[h - 1][w - 1]) { cout << 0 << '\n'; return 0; } const int t = h + w - 2; dp[0][0][h-1] = 1; mint ans; rep(i, h) rep(j, w) { int s1 = i + j; int s2 = t - s1; if (s1 == s2) { ans += dp[i][j][i]; break; } else if (s1 + 1 == s2) { ans += dp[i][j][i] + dp[i][j][i+1]; break; } else if (s1 < s2) { rep(k, h) if (int l = s2 - k; 0 <= l && l < w) { rep(k1, 2) rep(k2, 2) { int ni = i + di[k1], nj = j + dj[k1]; int nk = k - di[k2], nl = l - dj[k2]; if (0 <= ni && ni < h && 0 <= nj && nj < w && 0 <= nk && nk < h && 0 <= nl && nl < w && s[ni][nj] == s[nk][nl]) { dp[ni][nj][nk] += dp[i][j][k]; } } } } } cout << ans.val() << '\n'; }