제출 #1330212

#제출 시각아이디문제언어결과실행 시간메모리
1330212blackscreen1Palindromic Partitions (CEOI17_palindromic)C++20
100 / 100
39 ms1516 KiB
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll q, n, a, b, cc, ans;
string s;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> q;
	while (q--) {
		cin >> s;
		n = s.length();
		a = b = ans = 0;
		cc = 1;
		iloop(0, n/2) {
			a = (a * 31 + (s[i] - 'a' + 1))%MOD1;
			b = (cc * (s[n - i - 1] - 'a' + 1) + b)%MOD1;
			if (a == b) {
				a = b = 0;
				ans += 2;
				cc = 1;
			}
			else cc = (cc*31)%MOD1;
		}
		if (n%2 == 1 || a) ans++;
		cout << ans << "\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...