题目链接: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. JAVA字符串

    字符串   1. 字符串 1.1 字符串概述和特点 java.lang.String类代表字符串. API当中说:Java 程序中的所有字符串字面值(如 "abc" )都作为此类的 ...

  2. Maven安装及配置

    第1部分 准备 1.1 安装JDK和Eclipse: 1.2 下载Maven(https://maven.apache.org/download.cgi) 第2部分 2.1 安装Maven 2.1.1 ...

  3. JavaScript事件的属性列表

    HTML 4.0 的新特性之一是能够使 HTML 事件触发浏览器中的行为,比如当用户点击某个 HTML 元素时启动一段 JavaScript.下面是一个属性列表,可将之插入 HTML 标签以定义事件的 ...

  4. sublime 浏览器快捷键设置

    之前每次忘掉在哪打开,这次认真记一下 菜单栏Preferences-->Package Settings-->Side Bar-->Key Binding-Users [ // ch ...

  5. a标签跳页传参,以及截取URL参数

    <a href="dd.index?aa=1&&bb=2"></a> //截取URL参数 // console.log(window.loc ...

  6. PYthon3:简单几步实现冒泡排序

    1.概念理解: 冒泡排序:可以简单的理解为是列表中相近的元素,两两比较,小的在前面.最多需要len()-1次排序. 2.例子:a=[11,7,4,56,35,0] 3.代码实现: 4.输出结果: 第1 ...

  7. TestNg和spring3测试报错:Failed to read candidate component class-遁地龙卷风

    java.lang.IllegalStateException:Failed to load ApplicationContext Caused by: org.springframework.bea ...

  8. 【听大佬rqy分享有感】

    rqy,一个神奇的名字,一个神奇的物种. 初三自学高等数学,无师自通:获得了大大小小的oi奖项:是也一直是山东省信息学的“红太阳”:今天听了他的分享,真的很有帮助. 1.  不必太较真:遇到不会的高数 ...

  9. TP5报错

    Array to string conversion 数组不能用echo来输出,可使用var_dump().dump()或print_r()

  10. SecureCRT的安装与破解(过程很详细!!!)

    SecureCRT的安装与破解(过程很详细!!!) 使用SecureCRT可以方便用户在windows环境下对linux主机进行管理,这里为大家讲一下SecureCRT的破解方法,仅供大家参考学习: ...