[Codeforces Round #438][Codeforces 868D. Huge Strings]
题目链接: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]的更多相关文章
- [Codeforces Round #438][Codeforces 868C. Qualification Rounds]
题目链接:868C - Qualification Rounds 题目大意:有\(n\)个题目,\(k\)个人,每个人可能做过这\(n\)个题里的若干道,出题方要在这\(n\)个题目里选若干个出来作为 ...
- Codeforces Round #438 (Div.1+Div.2) 总结
本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...
- 【Codeforces Round 438 A B C D 四个题】
题目所在比赛的地址在这里呀 A. Bark to Unlock ·述大意: 输入一个目标串.然后输入n(1<=n<=100)个串,询问是否可以通过这些串收尾相接或者它本身拼出目 ...
- D. Huge Strings Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
http://codeforces.com/contest/868/problem/D 优化:两个串合并 原有状态+ 第一个串的尾部&第二个串的头部的状态 串变为第一个串的头部&第二个 ...
- Codeforces Round #438 D. Huge Strings
Description You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations a ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- 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 ...
- 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个由两个字符组成的字符串 ...
- 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 ...
随机推荐
- Java 基础知识点
很多 Java 基础的东西都忘记了, 有必要再复习一些基本的知识点. 本文主要参考 https://github.com/Snailclimb/JavaGuide ================== ...
- SCI,EI,ISTP
SCI: Science Citation Index EI: The Engineering Index ISTP: Index to Scientific & Technic ...
- 【codeforces 765F】Souvenirs
Description Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souv ...
- 锁定表头和固定列(Fixed table head and columns)
源码: /// <summary> /// 锁定表头和列 /// <para> sorex.cnblogs.com </para> /// </summary ...
- Python中应该使用%还是format来格式化字符串?
转载自http://www.cnblogs.com/liwenzhou/p/8570701.html %的特点是,前面有几个%,后面的括号里就得有几个参数,如果只有一个%,括号可以省略 基本格式 'a ...
- pythonのsqlalchemy多对多关系
现在来设计一个能描述“图书”与“作者”的关系的表结构,需求是 一本书可以有好几个作者一起出版 一个作者可以写好几本书 #!/usr/bin/env python from sqlalchemy imp ...
- Lua中的userdata
[话从这里说起] 在我发表<Lua中的类型与值>这篇文章时,就有读者给我留言了,说:你应该好好总结一下Lua中的function和userdata类型.现在是时候总结了.对于functio ...
- Mac 环境部署Docker私有仓库
docker的私有仓库类似maven的私服,一般用于公司内部搭建一个类似docker hub的环境,这样上传.下载镜像速度较快,本文将演示如何在mac上利用docker-machine搭建无需SSL证 ...
- Python-Django基础
django目录 -settings -urls -views ******强调:setting中'django.middleware.csrf.CsrfViewMiddleware'中间件先注释掉 ...
- Django 序列化-token
幂等性 幂等性:多次操作的结果和一次操作的结果是一样的 ,put请求是幂等的 post请求不是幂等的 序列化组件 全局和局部钩子函数 异常信息抛出过程 认证 路由里的,login.as_view() ...