博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 828C String Reconstruction 并查集(next跳)
阅读量:4331 次
发布时间:2019-06-06

本文共 2682 字,大约阅读时间需要 8 分钟。

String Reconstruction

 

Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one.

Ivan knows some information about the string s. Namely, he remembers, that string tioccurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.

You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers.

The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings tidoesn't exceed 1061 ≤ xi, j ≤ 1061 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide.

It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

Output

Print lexicographically minimal string that fits all the information Ivan remembers.

Examples

Input
3 a 4 1 3 5 7 ab 2 1 5 ca 1 4
Output
abacaba
Input
1 a 1 3
Output
aaa
Input
3 ab 1 1 aba 1 3 ab 2 3 5
Output
ababab 寻找一个字符串。给你一些线索(某些子串的位置),输出一个满足条件的最小字典序字符串。 暴力求解超时。可以采用并查集,若当前位置已经有子串放置,那就从已知子串的末尾继续放。并查集记录下末尾的下一位。很好的避免了重叠部分的重复枚举。有点像cys学长教过的那道next跳的题。 并查集套路题。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAX 2000005#define INF 0x3f3f3f3f#define MOD 1000000007using namespace std;typedef long long ll;int f[MAX];char a[MAX];int find(int x){ return f[x]==x?x:f[x]=find(f[x]);}int main(){ int n,m,x,len,i,j,k,ii; char s[MAX]; scanf("%d",&n); for(i=0;i<=2000000;i++){ a[i]='a'; f[i]=i; } int maxx=0; while(n--){ scanf(" %s %d",s,&k); len=strlen(s); for(j=1;j<=k;j++){ scanf("%d",&x); int xx=find(x); int ff=find(len+x); for(i=xx,ii=xx-x;i<=len+x-1;i++,ii++){ a[i]=s[ii]; f[find(i)]=ff; } if(len+x-1>maxx) maxx=len+x-1; } } for(i=1;i<=maxx;i++){ printf("%c",a[i]); } printf("\n"); return 0;}

 

 

转载于:https://www.cnblogs.com/yzm10/p/8808924.html

你可能感兴趣的文章
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>
VsVim - Shortcut Key (快捷键)
查看>>
C++练习 | 模板与泛式编程练习(1)
查看>>
HDU5447 Good Numbers
查看>>
08.CXF发布WebService(Java项目)
查看>>
java-集合框架
查看>>
RTMP
查看>>
求一个数的整数次方
查看>>
点云PCL中小细节
查看>>
铁路信号基础
查看>>
RobotFramework自动化2-自定义关键字
查看>>
[置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
查看>>
BABOK - 需求分析(Requirements Analysis)概述
查看>>
第43条:掌握GCD及操作队列的使用时机
查看>>
Windows autoKeras的下载与安装连接
查看>>
CMU Bomblab 答案
查看>>
微信支付之异步通知签名错误
查看>>
2016 - 1 -17 GCD学习总结
查看>>
linux安装php-redis扩展(转)
查看>>