Cod sursa(job #2916183)

Utilizator matwudemagogul matwu Data 28 iulie 2022 12:40:52
Problema Prefix Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define EFC cin.tie(nullptr)->ios_base::sync_with_stdio(false)
int d1[5] = { 0, -1, 0, 1, 0 };
int d2[5] = { 0, 0, 1, 0, -1 };
const int mod = 666013;
const int INF = 100000000;
int d11[9] = { 0 , -1, -1, 0, 1, 1, 1, 0, -1 };
int d22[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
int est[3] = { 0, -1, 0 };
int est1[3] = { 0, 0, 1 };
ifstream fin("prefix.in");
ofstream fout("prefix.out");


//----------------------------------


int N, pl[1000002];
string a;
void abrack() {
	
	fin >> a;
	a = '$' + a;
	int n = a.length(), k = 0, ans = 0;
	for (int i = 2; i <= n; i++) {
		while (k > 0 && a[k + 1] != a[i]) {
			k = pl[k];
		}
		if (a[k + 1] == a[i]) {
			k++;
		}
		pl[i] = k;
		if (pl[i] && (pl[i] % (i - pl[i]) == 0)) {
			ans = i;
		}
	}
	fout << ans << '\n';
}
int main(){
	
	fin >> N;
	while (N--) {
		abrack();
	}
}