-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFILRTEST.cpp
More file actions
50 lines (50 loc) · 1 KB
/
FILRTEST.cpp
File metadata and controls
50 lines (50 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int *Z_function(char s[])
{
int *z;
z = (int*)calloc((strlen(s)+9),sizeof(int));
int l=0,r=0,n = strlen(s);
z[0] = n;
for(int i=1;i<n;i++)
{
if(i<=r)
z[i] = min(r-i+1 , z[i-l]);
while(i+z[i] < n && s[z[i]] == s[i+z[i]])
z[i]++;
if(i+z[i]-1 > r)
l = i, r = i+ z[i] - 1;
}
return z;
}
int main()
{
int n;
while(1)
{
char s[1000009];
scanf("%d",&n);
scanf("%s",s);
if(n==-1)
return 0;
int *z;
int size = strlen(s);
if(n<size)
{
printf("0\n");
continue;
}
z = (int*)calloc((size+9),sizeof(int));
z = Z_function(s);
int m = 0;
for(int i=1;i<size;i++)
{
if(i+z[i] == size)
m = max(m , z[i]);
}
int total;
total = (n-m)/(size - m);
printf("%d\n",total);
}
return 0;
}