Codeforces 526 D Om Nom and necklace
Test instructions
Gives a string asking whether a string from 0 to P is in the format: S=a+b+a+b+a+...+a+b+a, where A, B is a string, and can be an empty string, for each position of the string p.
Limit:
String length 1e6
Ideas:
The flexible use of the next array.
/*codeforces 526 D Om Nom and necklace test instructions: gives a string asking whether a string from 0 to p conforms to the format for each position p for the string: S=a+b+a+b+a+...+a+b+a, where A, b is a string and can be an empty string. Limitations: string length 1e6 ideas: The flexible use of the next array. */#include <iostream> #include <cstdio>using namespace std;const int N = 1000005;int Nxt[n];char s[n], t[n]; int Slen, tlen;void getNext () {int i,j;j=nxt[0]=-1;for (int i=1;i<tlen;++i) {while (J!=-1 && t[i]!=t[j+1]) j= Nxt[j];if (T[j+1]==t[i]) j++;nxt[i]=j;} Char Ans[n];bool zc[n];int main () {int n,k;scanf ("%d%d", &n,&k), scanf ("%s", T), Tlen=n;getnext ();//for (int i=1; I<=n;++i) {//cout<<i<< "<<nxt[i]<<endl;//}for (int i=0;i<n;++i) {int P=i+1;int bl=p/( P-1-NXT[P-1]), if (p% (p-1-nxt[p-1)) ==0) {if (bl/k>=bl%k) Putchar (' 1 '); else Putchar (' 0 ');} Else{if (bl/k>bl%k) Putchar (' 1 '); else Putchar (' 0 ');}} Puts (""); return 0;}
Codeforces 526 D Om Nom and necklace next array for flexible use