結果
問題 | No.599 回文かい |
ユーザー |
|
提出日時 | 2017-11-27 12:10:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 119 ms / 4,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 550 ms |
コンパイル使用メモリ | 71,128 KB |
実行使用メモリ | 102,144 KB |
最終ジャッジ日時 | 2024-11-27 10:55:56 |
合計ジャッジ時間 | 1,986 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#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 - 1; 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] = 0; } } } 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 + 2) / 2; i++) { to(ans, dp[i]); } cout << ans << endl; }