結果

問題 No.599 回文かい
ユーザー ats5515ats5515
提出日時 2017-11-24 23:09:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 240 ms / 4,000 ms
コード長 1,234 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 79,568 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 05:11:30
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 20 ms
4,376 KB
testcase_12 AC 36 ms
4,384 KB
testcase_13 AC 22 ms
4,380 KB
testcase_14 AC 61 ms
4,376 KB
testcase_15 AC 67 ms
4,376 KB
testcase_16 AC 210 ms
4,376 KB
testcase_17 AC 240 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
evil_0.txt AC 47 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	//S.clear();
	
	int N = S.size();
	vector<int> A(N);
	int res = 0;
	vector<int> dp((N / 2) + 2, 0);
	dp[0] = 1;
	int nn = N;
	for (int x = 0; x < nn / 2; x++) {
		N = S.size();
		A[x] = S.size();
		int i = 1, j = 0;
		for (int i = 0; i < N; i++) {
			A[i] = 0;
		}
		while (i < S.size()) {
			while (i + j < S.size() && S[j] == S[i + j]) ++j;
			A[i] = j;
			if (j == 0) { ++i; continue; }
			int k = 1;
			while (i + k < S.size() && k + A[k] < j) A[i + k] = A[k], ++k;
			i += k; j -= k;
		}
		S.pop_back();
		S.erase(S.begin());
	
		for (int k = ((N - 1) / 2) + 1; k < N; k++) {
			if (A[k] == N - k) {
				//cerr << x << " " << x + N - k << endl;
				dp[x + N - k] = (dp[x + N - k] + dp[x]) % MOD;
			}
		}
		//cerr << dp[x] << endl;
		//res = (res + dp[x]) % MOD;
	}
	for (int i = 0; i < dp.size(); i++) {
		//cerr << dp[i] << " ";
		res = (res + dp[i]) % MOD;
	}
	//cerr << endl;
	cout << res << endl;
}
0