cogs696 longest prefix

cogs696 longest prefix


原题链接


IOI1996原题?
其实这题我不会。
map+string+手动氧气大法好
//就是这么皮(滑稽


Code

// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#define Fname "prefix"
#pragma GCC optimize(2)
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
typedef long long ll;
il int gi(){
    rg int x=0;rg char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x;
}
map<string,bool>Map;
bool f[200010];
int main(){
    freopen(Fname".in","r",stdin);
    freopen(Fname".out","w",stdout);
    string s,S("%");
    while(cin>>s,s!=".")Map[s]=1;
    while(cin>>s)S+=s;
    int len=S.size()-1;
    int p=1;
    while((p<=len)&&(Map.find(S.substr(1,p))==Map.end()))++p;
    f[0]=f[p]=1;
    if(p==len+1){puts("0");return 0;}
    int ans=p;
    rep(i,p+1,len)rep(j,max(i-10,0),i-1)if(f[j]&&Map.find(S.substr(j+1,i-j))!=Map.end()){f[i]=1,ans=i;break;}
    printf("%d\n",ans);
    return 0;
}
posted @ 2017-09-18 22:44  菜狗xzz  阅读(110)  评论(0编辑  收藏  举报