题目链接:868D - Huge Strings

题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值。定义一个新串的价值\(k\)为:最大的\(k\),使得这个新串包含所有长度为\(k\)的01串(这样的字符串有\(2^k\)个)

题解:首先来证明对于任何的串,这个\(k\)的值不会超过9

   若\(k=10\),由所有字符串的长度总和不超过100,因此在初始的\(n\)个串里,互不相同的长度为\(k\)的子串不超过100个。又由于每次连接最多能产生9个新的长度为\(k\)的子串(即横跨两个字符串之间的子串),因此互不相同的子串个数最多为\(9 \cdot100+100<2^k\),故\(k<10\)

   接下来就只需要记录每个字符串的前缀,后缀以及长度为\(k\)的子串有哪些就好了。

#include<bits/stdc++.h>
using namespace std;
#define N 101
int n,m,a,b;
struct rua
{
string st,ed;
set<int>has[];
bool check(int k)
{
for(int i=;i<(<<k);i++)
if(!has[k].count(i))return false;
return true;
}
int ans()
{
for(int k=;k>;k--)
if(check(k))return k;
return ;
}
rua connect(rua nxt)
{
rua res=nxt;
res.st=st;
if(st.size()<)
res.st=st+nxt.st.substr(,min(nxt.st.size(),-st.size()));
int cpy_len=min(ed.size(),-nxt.ed.size());
if(nxt.ed.size()<)
res.ed=ed.substr(ed.size()-cpy_len,cpy_len)+nxt.ed;
for(int k=;k<=;k++)
for(auto i:has[k])res.has[k].insert(i);
string tmp=ed+nxt.st;
int len=tmp.size();
for(int i=;i<len;i++)
{
int value=;
for(int d=;d< && i+d<len;d++)
value=value*+tmp[i+d]-'',
res.has[d+].insert(value);
}
return res;
}
}f[*N];
string s;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
cin>>s;
int len=s.size();
for(int j=;j<len;j++)
{
int value=;
for(int d=;d< && j+d<len;d++)
value=value*+s[j+d]-'',
f[i].has[d+].insert(value);
}
int cpy_len=min(,len);
f[i].st=s.substr(,cpy_len);
f[i].ed=s.substr(len-cpy_len,cpy_len);
}
scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
f[n+i]=f[a].connect(f[b]);
printf("%d\n",f[n+i].ans());
}
}

[Codeforces Round #438][Codeforces 868D. Huge Strings]的更多相关文章

  1. [Codeforces Round #438][Codeforces 868C. Qualification Rounds]

    题目链接:868C - Qualification Rounds 题目大意:有\(n\)个题目,\(k\)个人,每个人可能做过这\(n\)个题里的若干道,出题方要在这\(n\)个题目里选若干个出来作为 ...

  2. Codeforces Round #438 (Div.1+Div.2) 总结

    本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...

  3. 【Codeforces Round 438 A B C D 四个题】

    题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意:       输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...

  4. D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

    http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个 ...

  5. Codeforces Round #438 D. Huge Strings

    Description You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations a ...

  6. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  7. Codeforces Round #188 (Div. 2) B. Strings of Power 水题

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  8. Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

    A. Bark to Unlock 题目链接:http://codeforces.com/contest/868/problem/A 题目意思:密码是两个字符组成的,现在你有n个由两个字符组成的字符串 ...

  9. Codeforces Round #438 B. Race Against Time

    Description Have you ever tried to explain to the coordinator, why it is eight hours to the contest ...

随机推荐

  1. requests session operation

    # encoding:utf-8# baseic usage of requests.sessionsimport requestsfrom requests import sessions r = ...

  2. Blender 2.78 突然卡顿

    之前一直好好的直到这两天打开就一直延迟半拍,重启重装无效. 解决方法: NVIDIA控制面板→管理3d设置→程序设置→选择blender,更改显卡为集成显卡→应用 亲测有效.

  3. vue知多少,你对vue的认识比别人高在哪?

    1.beforeCreated/created区别? beforeCreated钩子能干什么 2.data中使用props 3.get/set依赖收集 get收集依赖(观察者) set 观察者重新求值 ...

  4. vue之vuex学习

    知识点一:vuex是状态管理器(单向数据流) 每个Vuex应用程序的核心是商店.“商店”基本上是一个容纳您的应用程序状态的容器.有两件事使Vuex商店与普通的全局对象不同: Vuex商店是被动的.当V ...

  5. ActiveMQ简单介绍及安装

    消息中间件 我们简单的介绍一下消息中间件,对它有一个基本认识就好,消息中间件(MOM:Message Orient middleware). 消息中间件有很多的用途和优点: 1. 将数据从一个应用程序 ...

  6. Beta冲刺(5/7)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:beta冲刺(5/7) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 ppt制作中 数据集标注 接下来的计划 制作p ...

  7. setTimeout 第三个参数秒懂

    好吧,假设你们都是从 ES6 里 promise 发现 setTimeout 还有第三个参数的,下面讲讲到底是干嘛的 setTimeout 第三个及之后的参数作用:定时器启动时候,第三个以后的参数是作 ...

  8. ES--06

    第51.初识搜索引擎_上机动手实战多搜索条件组合查询 课程大纲 GET /website/article/_search{ "query": { "bool": ...

  9. python结合pyvmomi批量关闭vmware虚拟机

    #!/usr/bin/env python #参考https://github.com/vmware/pyvmomi/blob/master/sample/poweronvm.py "&qu ...

  10. NOIP基本算法

    NOIP基本算法 1.二分 poj 2018 Best Cow Fences ▪ http://poj.org/problem?id=2018 ▪ 题意:给定一个正整数数列