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;}
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423 (Div. 2) C. String Reconstruction(字符串)
- Codeforces Round #423 (Div. 2) C. String Reconstruction
- Codeforces Round #423 (Div. 2) C. String Reconstruction(思维 模拟)
- Codeforces Round #423 (Div. 2) C String Reconstruction 并查集
- Codeforces Round #423 (Div. 2) C. String Reconstruction思维 D. High Load 构造
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- CodeForces 828C String Reconstruction
- Codeforces 828 C String Reconstruction
- codeforces 828C. String Reconstruction
- CF Round #423 Div. 2 C. String Reconstruction D. High Load 【思维】
- Codeforces 828 C. String Reconstruction 思维
- CodeForces 828C String Reconstruction(思维)
- CF 423 C : String Reconstruction
- String Reconstruction CodeForces
- codeforces 828 c String Reconstruction(扫描线+string)
- Codeforces 828C String Reconstruction【思维+并查集】
- 资源学习网站
- Codeforces #423-Div. 2-B. Black Square
- [js项目]封装库-CSS[下]
- 用一个实例介绍Java多线程
- [js项目]封装库-下拉菜单
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423(Div.2)
- android直播app礼物连击动画效果
- [高频] 五. 如何高效实现搜索类题目
- AndroidStudio与Eclipse的安装建议
- qml 自定义滑动条(官方example)
- 2017年7月8日休斯敦清华校友群主讲:API经济
- ArrayList 与 List
- 《MySQL技术内幕》编写C程序示例代码勘误