Codeforces #423-Div. 2-C. String Reconstruction

来源:互联网 发布:淘宝信用借贷逾期 编辑:程序博客网 时间:2024/06/05 02:36

C. String Reconstruction

time limit per test2 seconds
memory limit per test256 megabytes

题目

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

input3a 4 1 3 5 7ab 2 1 5ca 1 4outputabacabainput1a 1 3outputaaainput3ab 1 1aba 1 3ab 2 3 5outputababab

题意:

前面的故事就不讲了,直接说意思题目就是说,输入n行每一行开头一个字符串,然后告诉你这个字符串在总字符串的k个位置,然后让你输出字典序最小的总串

思路:

因为有很多重复的所以直接做很可能会超时,我的想法就是,先把每个串存下来,碰到相同位置的串保留字典序大的那个也就是长的那个,这样可以减少一部分重复,然后遍历输出一遍字符串,因为要求字典序最小所以,没有给出字符的地方输出‘a’。

代码:

#include <bits/stdc++.h>using namespace std;string s[1000005],ans;char str[1000005];int main(){    std::ios::sync_with_stdio(false);    int n,m,k,maxx=0,sizee;    cin>>n;    set<int>se;    while(n--)    {        cin>>ans>>m;        sizee=ans.size();        for(int i=0;i<m;i++)        {            cin>>k;se.insert(k);            if(ans>s[k])s[k]=ans;            if(k+sizee-1>maxx)maxx=k+sizee-1;        }    }    for(set<int>::iterator it=se.begin();it!=se.end();it++)    {            copy(s[*it].begin(),s[*it].end(),str+*it-1);    }    for(int i=0;i<maxx;i++)    {        if(str[i]<'a')cout<<'a';        else cout<<str[i];    }    cout<<endl;    return 0;}
阅读全文
0 0
原创粉丝点击