[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 ...
随机推荐
- docker下安装mysql
docker run -d -p 3306:3306 -v /root/docker/mysql/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf -v /root ...
- html css hover也会冒泡
<HEAD> <style type="text/css"> div:hover { color:blue !important; } </style ...
- Excel 当前行高亮
格式-条件格式-条件(公式)- =ROW()=CELL("row") 再选颜色...即可.
- [再寄小读者之数学篇](2014-06-26 Besov space estimates)
(1) $$\bex \sen{D^k f}_{\dot B^s_{p,q}}\sim \sen{f}_{\dot B^{s+k}_{p,q}}. \eex$$ (2) $$\beex \bea &a ...
- 一个QQ旋风的BUG
本人喜欢用QQ旋风下载工具,很不幸的是这个工具BUG太多了. 下载不同COOKIE,相同文件名.URL的文件时候会QQ旋风崩溃. 感兴趣可以试下.
- CentOS7.3安装VirtualBox
安装 DKMS.更新内核 # yum -y install gcc make glibc kernel-headers kernel-devel dkms Installed: dkms.noar ...
- Centos7 安装 tree
Centos7 安装 tree 用命令 yum 安装 tree yum -y install tree
- 编译Android ROM环境搭建
环境搭建 1 安装ubuntu 推荐12.04或13.10 2 安装jdk7和一些所需要的包安装jdk7$ sudo apt-get update$ sudo apt-get install open ...
- EmbeddedSolrServer的使用与solor6.3.0的使用
1. 到solr官网下载对应版本的solr: https://lucene.apache.org/solr/ 我下载的是:6.3.0版本(需要JDK8),solr默认集成了jetty容器,而且在 ...
- day03 数据类型与运算符
今日内容: 1.变量及常量的命名规范 2.与用户的交互 3.字符串的格式化输出 4.基本的数据类型 5.运算符 6.注释 今日重点: 1.变量及常量的命名规范 (1)强制规范[如果违反会报错] 1&g ...