結果

問題 No.599 回文かい
ユーザー eto_nagisaeto_nagisa
提出日時 2017-11-24 22:55:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 4,000 ms
コード長 1,953 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 150,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 05:04:07
合計ジャッジ時間 2,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
typedef unsigned long long ull;

struct RollingHash
{
	vector<ull> hash, pow;
	RollingHash(string s, ull _b = 1000000007)
	{
		int sz = s.length();
		hash.assign(sz + 1, 0);
		pow.assign(sz + 1, 0);

		pow[0] = 1;
		for (int i = 0; i<sz; i++) {
			pow[i + 1] = pow[i] * _b;
		}
		for (int i = 0; i<sz; i++) {
			hash[i + 1] = (hash[i] + s[i])*_b;
		}
	}
	
	ull get(int l, int r) {
		return (hash[r] - hash[l] * pow[r - l]);
	}
};


int n;
int dfs(vi &dp,RollingHash &rh, string &s, int l) {
	
	if (dp[l] != -1)return dp[l];
	if (n % 2 == 1 && l == n / 2)return dp[l] = 1;
	int ret = 0;
	FOR(i, l, n/ 2) {
		if (rh.get(l, i+1) == rh.get(n - l - (i - l+1), n - l)) {
			ret += dfs(dp,rh, s, i+1);
			ret %= MOD;
		}
	}
	return dp[l] = (ret+1)%MOD;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	RollingHash rh = RollingHash(s);
	n = s.size();
	vi dp(n, -1);
	dfs(dp,rh, s, 0);
	cout << dp[0]<< endl;
}
0