제출 #113897

#제출 시각아이디문제언어결과실행 시간메모리
113897MAMBAPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
95 ms1812 KiB
#include <bits/stdc++.h> 

using namespace std;

#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef complex<ld> point;
typedef pair<ld , ld> pld;
typedef vector<ll> vi;

inline void fileIO(string s) {
	//	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

template<class T , class S>
inline bool smin(T &a, S b) { return (T)b < a ? a = b , 1 : 0; }
template<class T , class S>
inline bool smax(T &a, S b) { return a < (T)b ? a = b , 1 : 0; }

constexpr int N = 1e5 + 10;
constexpr int MOD = 1e9 + 7;

template<typename T>
inline T mod(T &v) { return v = (v % MOD + MOD) % MOD; }
template<typename S, typename T>
inline S add(S &l, T r) { return mod(l += r); }

string s;
int t;

int solve(int l, int r) {
	if (l == r) return 1;
	if (l > r) return 0;

	ll H1 = s[l], H2 = s[r], shit = 1;
	while (true) {
		if (l > r) return 1;
		if (H1 == H2) 
			return 2 + solve(l + 1, r - 1);
		l++, r--; shit = (shit * 727) % MOD;
		H1 = (727 * H1 + s[l]) % MOD;
		H2 = (H2 + shit * s[r]) % MOD;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> t;
	while (t--) {
		cin >> s;
		cout << solve(0 , s.size() - 1) << '\n';
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...