codeforces 828C. String Reconstruction
来源:互联网 发布:淘宝超级运动会是什么 编辑:程序博客网 时间:2024/06/05 02:24
codeforces 828C. String Reconstruction
abstract
将每个位置与每个位置的字符串存储,并构造cmp函数根据位置增加优先,字符串长度减少的顺序进行排序,提供findnext函数寻找下一个存储点的位置。其有三种情况:
- 下个存储点的位置刚好连接在当前结果的后面,此时直接将该存储点对应的字符串添加到结果之后;
- 下个存储点的位置在当前结果的后面,此时需要加 a ,加的数量根据此时结果的长度和下个存储点的位置得到,添加完后将其添加到结果之后;
- 在当前结果之前,此时需忽略该字符串前面部分长度,然后将后半部分一个一个添加到结果中。
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
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
#include<iostream>#include<algorithm> #include<string.h>#include<string>#include<stdio.h>#define ll long longusing namespace std;ll k; string ans;struct node{ ll p; ll to;};string sno[1000005];int cmp(node a,node b){ if(a.p<b.p)return 1; else if(a.p==b.p) { return sno[a.to].size()>sno[b.to].size(); } return 0;}node no[1000005];int find_next(int n){ //cout<<"ans"<<" "<<ans<<endl; for(int i=n+1;i<k;i++) { if(no[i].p==no[n].p)continue; else return i; } return -1;}int main(){ int t,pp; char ss[1000005]; scanf("%d",&t); k=0; for(int i=1;i<=t;i++) { cin>>sno[i]; int n; scanf("%d",&n); while(n--) { scanf("%d",&pp); no[k].to=i; no[k++].p=pp; } } sort(no,no+k,cmp); ll old=0; /*for(int i=0;i<k;i++) cout<<no[i].p<<sno[no[i].to]<<endl;*/ for(int i=0;i<no[0].p-1;i++) ans+='a'; ans+=sno[no[0].to]; while(1) { ll next=find_next(old); if(next==-1)break; if(no[next].p==ans.size()+1) { ans+=sno[no[next].to]; old=next; }else if(no[next].p<=ans.size()) { for(int i=ans.size()-no[next].p+1;i<sno[no[next].to].size();i++) ans+=sno[no[next].to][i]; old=next; }else {//cout<<"test "<<no[next].p<<" "<<ans.size()<<endl; int tmp=ans.size(); //cout<<"size"<<ans.size()<<endl; for(int i=0;i<no[next].p-tmp-1;i++) { ans+='a'; //cout<<i<<": "<<ans<<endl; } ans+=sno[no[next].to]; old=next; } //cout<<ans<<endl; } cout<<ans<<endl;}
- CodeForces 828C String Reconstruction
- Codeforces 828 C String Reconstruction
- codeforces 828C. String Reconstruction
- Codeforces 828 C. String Reconstruction 思维
- CodeForces 828C String Reconstruction(思维)
- codeforces 828 c String Reconstruction(扫描线+string)
- Codeforces 828C String Reconstruction【思维+并查集】
- Codeforces #423-Div. 2-C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- Codeforces Round #423 C. String Reconstruction
- String Reconstruction CodeForces
- Codeforces 827A/828C String Reconstruction[线段树单点更新]
- Codeforces Round #423 (Div. 2) C. String Reconstruction(字符串)
- Codeforces Round #423 (Div. 2) C. String Reconstruction
- Codeforces #848C: String Reconstruction 题解之花样虐题
- CF 828C String Reconstruction(暴力)
- Codeforces828 C. String Reconstruction
- Codeforces828 C. String Reconstruction
- Codeforces 70D Professor's task [动态凸包]
- Chrome浏览器插件Postman用法简介-Http请求模拟工具
- 【图】图的相关概念以及图的存储
- wifi
- ElasticSearch学习笔记(七)请求的发送
- codeforces 828C. String Reconstruction
- 单机Hadoop的安装与使用
- 乱码过滤器
- 计算文本的宽高
- 【计算机视觉】全景相机
- 玲珑学院 1138 震惊,99%+的中国人都会算错的问题 【容斥】【技巧】
- 登录过滤器
- 无法将文件“..\bin\Debug \**.dll”复制到“bin\**.dll”。对路径“bin \**.dll”的访问被拒绝。
- 各种随机数