An original string, an unknown string, each time from Pos[i] overwrites the unknown string, asks the last string form, and determines whether there is a contradiction in the process.
POS is ascending in the process, so if the coverage does not overlap, then it is OK to determine whether a suffix of the original string is also a prefix. This can be computed with next array, z function, suffix array, and so on.
1#include <iostream>2#include <vector>3#include <algorithm>4#include <string>5#include <string.h>6#include <stdio.h>7#include <math.h>8#include <stdlib.h>9#include <queue>Ten#include <stack> One#include <map> A#include <Set> - - using namespacestd; the - Const intn=1e6+12345; - CharS[n]; - BOOLValid[n]; + intNext[n]; - voidGetNext (Char*word,intn=0){ +N= (n==0)?strlen (Word): n; AMemset (Next,0,sizeof(next)); at inti,j; - for(i=1; i<n;i++){ -j=i; - while(j) { -j=Next[j]; - if(word[i]==Word[j]) { innext[i+1]=j+1; - Break; to } + } - } the } * intPos[n]; $ intMain () {Panax Notoginseng intn,c; -scanf"%d%d",&n,&c); thescanf"%s", s); + intm=strlen (s); A GetNext (s,m); the for(intI=m;i;i=Next[i]) +valid[i]=true; - for(intI=1; i<=c;i++) $scanf"%d", pos+i); $pos[0]=-m;pos[++c]=n+1; - intSpace=0; - BOOLok=true; the for(intI=1; i<=c;i++) { -pos[i]--;Wuyi if(pos[i-1]+m>Pos[i]) { the if(!valid[m-pos[i]+pos[i-1]]) -ok=false; Wu } - Else { Aboutspace+=pos[i]-(pos[i-1]+m); $ } - } - if(!OK) -cout<<0<<Endl; A Else { + Long Longret=1; the for(intI=1; i<=space;i++) -ret=ret*26ll%1000000007; $cout<<ret<<Endl; the } the return 0; the}View Code
CF 535D Next Array