Submission #447384

#TimeUsernameProblemLanguageResultExecution timeMemory
447384fuad27Palindromic Partitions (CEOI17_palindromic)C++14
100 / 100
80 ms11796 KiB
#include<iostream>
using namespace std;
#define int long long
#define mod (long long)(1e17-3)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int32_t main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	int t;
	cin >> t;
	while(t--) {
		string s;
		cin >> s;
		int ans = 0, n = s.length();
		long long hash1 = 0, hash2 = 0, pw = 1, cnt = 0, j = n;
		for(int i = 0;i<n/2;i++) {
			hash1 = (26*hash1%mod + (s[i] - 'a'))%mod;
			hash2 = (hash2+((s[n-i-1]-'a'))*pw%mod)%mod;
			if(hash1 == hash2){
				hash1 = 0;
				hash2 = 0;
				ans+=2;
				pw = 1;
				j = i;
			}
			else pw=26*pw%mod;
		}
		if(j!=(n/2)-1 or n%2)ans++;
		cout<<ans<<'\n';
	}
}

Compilation message (stderr)

palindromic.cpp: In function 'int32_t main()':
palindromic.cpp:17:43: warning: unused variable 'cnt' [-Wunused-variable]
   17 |   long long hash1 = 0, hash2 = 0, pw = 1, cnt = 0, j = 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...