zoukankan      html  css  js  c++  java
  • BZOJ4460 [Jsoi2013]广告计划

    题目

    蛤蛤题,数据范围这么小,于是怎么暴力怎么来

    既然保证有解,那么答案不会超过(L),于是我们枚举一个(k),看其能否成为答案

    有了(k)还不够,再枚举一个(j,j<k),表示这个单词不在一整列的前缀的长度为多少,有了(j,k)我们就能确定每一行的子串是什么了,于是往SAM上跑一跑,看看( m endpos)有没有交就好了

    复杂度大概是(O(L^3+frac{L^3n}{w})),非常不满

    代码

    #include<bits/stdc++.h>
    #define re register
    int m,n,lim,num;
    int lst,cnt;
    char S[205];
    std::bitset<100> ans,vis[20005];
    struct E{int v,nxt;}e[20005];
    int len[20005],fa[20005],head[20005],son[20005][26];
    inline void ins(int c,int o) {
    	int p=++cnt,f=lst;lst=p;
    	len[p]=len[f]+1,vis[p][o]=1;
    	while(f&&!son[f][c]) son[f][c]=p,f=fa[f];
    	if(!f) {fa[p]=1;return;}
    	int x=son[f][c];
    	if(len[f]+1==len[x]) {fa[p]=x;return;}
    	int y=++cnt;len[y]=len[f]+1,fa[y]=fa[x],fa[x]=fa[p]=y;
    	for(re int i=0;i<26;i++) son[y][i]=son[x][i];
    	while(f&&son[f][c]==x) son[f][c]=y,f=fa[f];
    }
    inline void add(int x,int y){e[++num].v=y;e[num].nxt=head[x];head[x]=num;}
    void dfs(int x) {
    	for(re int i=head[x];i;i=e[i].nxt) dfs(e[i].v),vis[x]|=vis[e[i].v];
    }
    int main() {
    	scanf("%d%d",&m,&n);cnt=1;
    	for(re int i=1;i<=m;i++) {
    		scanf("%s",S+1);lst=1;
    		for(re int j=1;j<=n;j++) ins(S[j]-'a',j-1);
    	}
    	for(re int i=2;i<=cnt;i++) add(fa[i],i);dfs(1);
    	scanf("%s",S+1);lim=strlen(S+1);
    	for(re int k=1;k<=lim;k++) {
    		int flag=0;
    		for(re int j=0;j<k;++j) {
    			for(re int i=0;i<n;i++) ans[i]=1;
    			int ml=0;
    			for(re int t=j+1;t<=k;t++) {
    				int nw=1,cnt=0;
    				for(re int p=t;p<=lim;p+=k)nw=son[nw][S[p]-'a'],++cnt;
    				if(!ml) ml=cnt;if(ml==cnt) ans&=vis[nw];
    				if(cnt<ml) ans&=(vis[nw]<<1);if(!(ans.any())) break;
    			}
    			for(re int t=1;t<=j;++t) {
    				int cnt=0,nw=1;
    				for(re int i=t;i<=lim;i+=k)++cnt,nw=son[nw][S[i]-'a'];
    				if(cnt>ml) ans&=vis[nw];if(cnt==ml) ans&=(vis[nw]<<1);
    				if(!(ans.any())) break;
    			}
    			flag=ans.any();
    			if(flag) break;
    		}
    		if(flag) {printf("%d
    ",k);break;}
    	}
    }
    
  • 相关阅读:
    [atAGC049E]Increment Decrement
    [atARC099F]Eating Symbols Hard
    [atARC099E]Independence
    [Codeforces] Codeforces Round #456
    Treap
    Splay树
    [Offer收割]编程练习赛42
    [Codeforces]Good Bye 2017
    Codeforces Round #455
    Educational Codeforces Round 35
  • 原文地址:https://www.cnblogs.com/asuldb/p/12031095.html
Copyright © 2011-2022 走看看