Codeforces 526 D Om Nom and necklace next array for flexible use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.