結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-24 22:55:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,039 bytes |
| コンパイル時間 | 1,431 ms |
| コンパイル使用メモリ | 170,216 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-27 07:46:17 |
| 合計ジャッジ時間 | 8,761 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
string s;
int n;
ll dp[10005];
ll solve(int cur) {
if (cur >= n / 2) return 0;
if (dp[cur] >= 0) return dp[cur];
ll res = 1;
string sl = "", sr = "";
for (int i = cur; i < n / 2; i++) {
sl += s[i];
sr = s[n - 1 - i] + sr;
if (i > cur && (sl.front() != s[n - 1 - i] || sr.back() != s[i])) continue;
(res += solve(i + 1)) %= MOD;
}
return dp[cur] = res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> s;
n = s.length();
dp[(n - 1) / 2] = 1;
if (n % 2 == 0) dp[(n - 1) / 2] += (s[(n - 1) / 2] == s[(n - 1) / 2 + 1]);
for (int i = (n - 1) / 2 - 1; i >= 0; i--) {
dp[i] = 1;
string sl = "", sr = "";
for (int j = i + 1; j <= (n - 1) / 2; j++) {
sl += s[j - 1];
sr = s[n - j] + sr;
if (sl == sr) (dp[i] += dp[j]) %= MOD;
}
}
cout << dp[0] << endl;
return 0;
}