Round #423 C. String Reconstruction(Div.2)

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 ti occurs 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 ti doesn‘t exceed 106, 1?≤?xi,?j?≤?106,1?≤?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

3a 4 1 3 5 7ab 2 1 5ca 1 4

output

abacaba

input

1a 1 3

output

aaa

input

3ab 1 1aba 1 3ab 2 3 5

output

ababab
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 const int INF=0x3f3f3f3f;
 6 char s[2000006];
 7 char ch[2000005];
 8
 9 int main(){
10         int n,m,x,tot=0;
11         scanf("%d",&n);
12         for(int i=0;i<n;i++){
13             scanf("%s%d",&ch,&m);
14             int k=strlen(ch);
15             int t=-INF;
16             for(int i=0;i<m;i++){
17                 scanf("%d",&x);
18                 x--;
19                 tot=max(x+k,tot);
20                 for(int l=max(x,t);l<x+k;l++)
21                     s[l]=ch[l-x];
22                 t=x+k;
23             }
24         }
25         for(int i=0;i<tot;i++)
26             if(s[i]==‘\0‘) printf("a");  //‘\0‘
27             else printf("%c",s[i]);
28             printf("\n");
29     return 0;
30 }
时间: 2024-08-27 11:25:27

Round #423 C. String Reconstruction(Div.2)的相关文章

Round #423 B. Black Square(Div.2)

Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that

Round #423 A.Restaurant Tables(Div.2)

In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. I

Codeforces Round #423 (Div. 2) C 思维,并查集 或 线段树 D 树构造,水

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction   思维,并查集 或 线段树 题意:一个字符串被删除了,但给出 n条信息,要还原出可能的字典序最小的字符串.信息有:字符串ti,ki个位置xi,表明原本的字符串在xi位置是以字符串ti开头的. tags:惨遭 fst,一开始把所有字符串都存下来,排序做的,结果爆内存了.. 方法1: 考虑并查集,对于字符串 ti,在位置xi,

Codeforces Round #423 (Div. 2) D. High Load(构造题)

题目链接:Codeforces Round #423 (Div. 2) D. High Load 题意: 给你一个数n和k,让你构造出一颗树,有k个叶子节点,使得这棵树的任意两个点的距离的最大值最小. 题解: 显然要使得这棵树的任意两个点的距离的最大值最小,每个点离树根越近越好. 然后要求有k个叶子节点,所以我就任意选一个点为根,然后构成一棵m叉的树就行了. 最大距离的最小值就是离根最远的和最近的加一加就行了. 1 #include<cstdio> 2 #define F(i,a,b) for

Codeforces Round #423 (Div. 2) A-C

A. Restaurant Tables 这里看错题意还wa了两发.... 按题意模拟就行了 水题 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #includ

Codeforces Round #423 (Div. 2)A B C D

A. Restaurant Tables 题意是一个点单人座有a个双人座有b个,有n组人,每组人有一个或两个人.当一个人时优先坐单人座的没有就坐没有人坐的双人座,然后才是在已经坐了一人的双人座,还没有就拒绝为他服务.当两个人时,只坐双人座的没有就拒绝服务.问这个店要拒绝服务多少人. 直接模拟下就行了. 1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 using namespace st

Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)

A.String Reconstruction B. High Load C. DNA Evolution 题意:给定一个只包含A,T,C,G的字符串S,有如下两种操作 1)修改一个点的字母. 2)给定一个字符串e ($\left | e \right |\leq 10$),生成一个由e重复组成的新串,eee...,问$S_{l..r}$中有几个字母跟这个新的字符串一一对应. SOL:对于每个字母,用BIT[x][y][L]表示$S_{1..L}$中,所有$\equiv x\left (mod

Educational Codeforces Round 25 F. String Compression(kmp+dp)

题目链接:Educational Codeforces Round 25 F. String Compression 题意: 给你一个字符串,让你压缩,问压缩后最小的长度是多少. 压缩的形式为x(...)x(...)  x表示(...)这个出现的次数. 题解: 考虑dp[i]表示前i个字符压缩后的最小长度. 转移方程解释看代码,这里要用到kmp来找最小的循环节. 当然还有一种找循环节的方式就是预处理lcp,然后通过枚举循环节的方式. 这里我用的kmp找的循环节.复杂度严格n2. 1 #inclu

Codeforces C - String Reconstruction

C - String Reconstruction 方法一:把确定的点的父亲节点设为下一个点,这样访问过的点的根节点都是没访问过的点. 代码: #include<bits/stdc++.h> using namespace std; const int N=1e6+5; char s[N],res[N*2]; int fa[N*2]; int Find(int x) { return x==fa[x]?x:fa[x]=Find(fa[x]); } int main() { for(int i=