結果

問題 No.599 回文かい
ユーザー idat_50meidat_50me
提出日時 2021-01-08 23:32:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 4,000 ms
コード長 4,106 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 202,136 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 12:32:58
合計ジャッジ時間 4,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/no/599"

#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif

vector<int> z_algorithm(const string &S) {
	int N = S.length();
	vector<int> res(N, 0);

	for(int i=1, c=0; i<N; i++) {
		int l = i-c;
		if(i+res[l] < c+res[c]) {
			res[i] = res[l];
		}
		else {
			int l = max(c+res[c]-i, 0);
			while(i+l<N && S[l]==S[i+l]) l++;
			res[i] = l;
			c = i;
		}
	}

	res[0] = N;
	return res;
}

template<int mod>
struct mint {
private:

	long long val;

public:

	mint(long long x=0) : val((mod+x%mod)%mod) {}

private:
	mint inv() const {
		long long x_ = val, xd = 1, xdd = 0,
		          y_ = mod, yd = 0, ydd = 1,
		          div;
		
		while(true) {
			if(!y_) return mint(xd);
			div = x_/y_;
			x_  -= div*y_;
			xd  -= div*yd;
			xdd -= div*ydd;

			if(!x_) return mint(yd);
			div = y_/x_;
			y_  -= div*x_;
			yd  -= div*xd;
			ydd -= div*xdd;
		}
	}

public:

	mint operator-() const {
		return mint(-val);
	}

	mint& operator+=(const mint& a) {
		val += a.val;
		if(val >= mod) val -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		val -= a.val;
		if(val < 0) val += mod;
		return *this;
	}
	mint& operator*=(const mint& a) {
		(val*=a.val) %= mod;
		return *this;
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint& operator+=(const long long& a) {
		(val+=mod+a%mod) %= mod;
		return *this;
	}
	mint& operator-=(const long long& a) {
		(val+=mod-a%mod) %= mod;
		return *this;
	}
	mint& operator*=(const long long& a) {
		(val*=mod+a%mod) %= mod;
		return *this;
	}
	mint& operator/=(const long long& a) {
		return (*this)/=mint(a);
	}

	mint operator+(const mint& a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res*=a;
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res/=a;
	}
	mint operator+(const long long& a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const long long& a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const long long& a) const {
		mint res(*this);
		return res*=a;
	}
	mint operator/(const long long& a) const {
		mint res(*this);
		return res/=mint(a);
	}

	mint& operator++() {
		(++val) %= mod;
		return *this;
	}
	mint operator++(int) {
		mint res(*this);
		(++val) %= mod;
		return res;
	}
	mint& operator--() {
		(val+=mod-1) %= mod;
		return *this;
	}
	mint operator--(int) {
		mint res(*this);
		(val+=mod-1) %= mod;
		return res;
	}

	bool operator==(const mint& a) const {
		return val == a.val;
	}
	bool operator!=(const mint& a) const {
		return val != a.val;
	}
	bool operator<(const mint& a) const {
		return val < a.val;
	}
	bool operator>(const mint& a) const {
		return val > a.val;
	}
	bool operator<=(const mint& a) const {
		return val <= a.val;
	}
	bool operator>=(const mint& a) const {
		return val >= a.val;
	}
	bool operator==(const long long& a) const {
		return val == a;
	}
	bool operator!=(const long long& a) const {
		return val != a;
	}
	bool operator<(const long long& a) const {
		return val < a;
	}
	bool operator>(const long long& a) const {
		return val > a;
	}
	bool operator<=(const long long& a) const {
		return val <= a;
	}
	bool operator>=(const long long& a) const {
		return val >= a;
	}

	mint& operator=(const mint& a) {
		val = a.val;
		return *this;
	}
	mint& operator=(const long long& a) {
		val = (mod+a%mod)%mod;
		return *this;
	}

	friend ostream& operator<<(ostream& os, const mint& a) {
		return os << a.val;
	}
	friend istream& operator>>(istream& is, mint &a) {
		long long n;
		is >> n;
		a = mint(n);
		return is;
	}
};


using mi = mint<1000000007>;

int main() {
	string S; cin>>S;
	vector<mi> dp(S.length()/2+1, 0);
	dp[0] = 1;

	for(int i=0; i<=(S.length()-1)/2; i++) {
		vector<int> v = z_algorithm(string(S.begin()+i, S.end()-i));
		for(int j=1; j<=v.size()/2; j++) {
			if(v[v.size()-j]==j) dp[i+j] += dp[i];
		}
	}

	cout<<accumulate(dp.begin(), dp.end(), mi(0))<<endl;
}
0