codeforce 827A String Reconstruction(模拟)
来源:互联网 发布:mac系统修复软件 编辑:程序博客网 时间:2024/06/05 03:16
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.
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.
Print lexicographically minimal string that fits all the information Ivan remembers.
3a 4 1 3 5 7ab 2 1 5ca 1 4
abacaba
1a 1 3
aaa
3ab 1 1aba 1 3ab 2 3 5
ababab
想到了直接模拟,但会超时,由于数据比较大此时就要考虑更新串之间重合的情况,如果发生重合,直接从重合的下一点开始赋值
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<vector>#include<math.h>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;char s[3000005];string temp;int main(){ int n,m,x,maxx=0; scanf("%d",&n); for(int i=0; i<3000005; i++) s[i]='a'; for(int i=1; i<=n; i++) { cin>>temp; scanf("%d",&m); int pre=-10000001; for(int j=1; j<=m; j++) { scanf("%d",&x); if(x-pre>=temp.length()) { for(int k=0; k<temp.length(); k++) { s[x+k]=temp[k]; } } else { int c=0; for(int k=x-pre;k>0;k--) { s[pre+temp.length()+c]=temp[temp.length()-k]; c++; } } pre=x; maxx=max(maxx,x+(int)temp.length()); } } s[maxx]='\0'; printf("%s",s+1);}
- codeforce 827A String Reconstruction(模拟)
- Codeforces 827A. String Reconstruction
- CodeFroces 827A.String Reconstruction
- codeforce-A. Gabriel and Caterpillar(模拟)
- Codeforces 827A/828C String Reconstruction[线段树单点更新]
- CodeForce 710E - Generate a String(dp)
- 【CodeForce 710E】Generate a String
- Codeforce A
- codeforce D. Innokenty and a Football League 贪心,模拟
- Codeforce 780D Innokenty and a Football League (贪心+模拟)
- CodeForce 825B Five-In-a-Row<简单模拟>
- Codeforce 893A Chess For Three (模拟)
- Codeforces828 C. String Reconstruction
- Codeforces828 C. String Reconstruction
- String Reconstruction CodeForces
- CodeForce 19A World Football Cup (string类应用)
- Codeforces Round #423 (Div. 2) C. String Reconstruction(思维 模拟)
- 【模拟】Codeforce 302B
- JAVA-去掉LIST中重复值
- 未来币-概念介绍-货币系统 Monetary System
- JS中定义对象的几种方式
- Linux系统、版本、CPU、内存查看、硬盘空间
- Git Commit failed with error The Git process exited with the code -1,073,741,819
- codeforce 827A String Reconstruction(模拟)
- JPush极光推送Java服务器端
- debian切换为root用户
- 实现一套代码开发多个应用
- 20170712智慧运营平台工作
- 根据类名寻找Maven依赖
- linux下为程序创建启动和关闭的的sh文件,scrapyd为例
- android studio 中编译C生成.so文件
- 【怎样写代码】偷窥高手 -- 反射技术(三):深入窥视字段