巅峰赛第8场代码
#include<bits/stdc++.h> using namespace std; #define LL long long #define debug(x) cerr<<#x<<" = "<<x #define sp <<" " #define el <<endl #define fgx cerr<<" ---------------------- "<<endl #define uint unsigned int #define ULL unsigned long long #define DB double #define LDB long double #define pii pair<int,int> #define mpt make_pair #define pb push_back #define fr first #define sc second #define M 1000020//Size #define INF 1000000000 #define INFLL 1000000000000000000 inline int read(){ int nm=0,fh=1; char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') fh=-1; for(;isdigit(c);c=getchar()) nm=nm*10+c-'0'; return nm*fh; } #define mod 1000000007//About inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);} inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);} inline int mul(LL x,LL y){return x*y%mod;} inline void upd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);} inline void dec(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);} inline int qpow(int x,LL sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;} int n,nt[M]; class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n int整型 节点个数 * @param u int整型vector * @param v int整型vector * @return int整型 */ int solve(string s) { // write code here n=s.size(),s='$'+s; int j=0; for(int i=2;i<=n;i++){ while(j&&s[i]!=s[j+1]) j=nt[j]; if(s[i]==s[j+1]) j++; nt[i]=j; } return (!nt[n])?-1:nt[n]; } }t;
#题解#