結果
問題 |
No.599 回文かい
|
ユーザー |
|
提出日時 | 2017-11-27 11:59:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 895 bytes |
コンパイル時間 | 522 ms |
コンパイル使用メモリ | 70,784 KB |
実行使用メモリ | 102,144 KB |
最終ジャッジ日時 | 2024-11-27 10:55:38 |
合計ジャッジ時間 | 1,957 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 18 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; const long long mod = 1e9 + 7; int dp[5050]; int lcp[5050][5050]; void to(int &x, int y) { x += y; if (x >= mod) { x -= mod; } } int main() { string s; cin >> s; const int n = s.size(); dp[0] = 1; for (int i = (n - 1) / 2; i >= 0; i--) { for (int j = n; j >= n / 2; j--) { if (s[i] == s[j]) { lcp[i][j - n / 2] = lcp[i + 1][j - n / 2 + 1] + 1; } else { lcp[i][j - n / 2] = lcp[i + 1][j - n / 2 + 1]; } } } for (int i = 0; i * 2 < n; i++) { for (int j = i; j * 2 < n; j++) { // s[i..j] == s[n-1-j..n-1-i] if (lcp[i][n - 1 - j - n / 2] >= j - i + 1) { to(dp[j + 1], dp[i]); } } } int ans = 0; for (int i = 0; i <= (n - 1) / 2; i++) { to(ans, dp[i]); } cout << ans << endl; }