C. String Reconstruction
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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

官方题解:

一开始sort排序,然后依次按顺序放入字符串

直接看代码(注意,输入需改为scanf格式,否则会超时)

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxn=1e6+100; string s[maxn];
vector<pair<int ,int> >tmp; int main()
{
int n,k,x;
scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>s[i]>>k;
for(int j=0;j<k;j++)
{
scanf("%d",&x);
tmp.push_back(make_pair(x,i));
}
}
sort(tmp.begin(),tmp.end());
string ans;
int len=1;
for(int i=0;i<tmp.size();i++)
{
int t1=tmp[i].first,t2=tmp[i].second;
while(t1>len)
{
ans+='a';
len++;
}//len-t1可以避免重复添加
for(int j=len-t1;j<s[t2].length();j++)
{
ans+=s[t2][j];
len++;
}
}
cout<<ans<<endl;
return 0;
}





Codefoces 828C的更多相关文章

  1. Codefoces 432C Prime Swaps(数论+贪心)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26094917 题目连接:Codefoces ...

  2. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  3. codefoces round193a

    link: http://codeforces.com/contest/332/problem/A /* ID: zypz4571 LANG: C++ TASK: 193a.cpp */ #inclu ...

  4. Codefoces 429 D. Tricky Function

    裸的近期点对.... D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codefoces 432 C. Prime Swaps

    哥德巴赫猜想: 任一大于2的偶数,都可表示成两个素数之和. 任一大于5的整数都可写成三个质数之和. 贪心取尽可能大的素数..... C. Prime Swaps time limit per test ...

  6. Codefoces 723B Text Document Analysis

    B. Text Document Analysis time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  7. Codefoces 723A The New Year: Meeting Friends

    A. The New Year: Meeting Friends time limit per test:1 second memory limit per test:256 megabytes in ...

  8. Codefoces Gym 101652 【最大连续和】

    <题目链接> 题目大意: 给你一段只由 'B'和'R'组成的字符串,问你在连续的区间内,"B"和"R"的差值最大是多少,输出该区间:如果对于差值相等 ...

  9. Codefoces 277 E. Binary Tree on Plane

    题目链接:http://codeforces.com/problemset/problem/277/E 参考了这篇题解:http://blog.csdn.net/Sakai_Masato/articl ...

随机推荐

  1. Bzoj3038 上帝造题的七分钟2 线段树

    Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1135  Solved: 509 Description XLk觉得<上帝造题的七分钟>不太 ...

  2. JDBC的数据类型

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/data-types.html: JDBC驱动程序在将Java数据类型发送到数据库之前,会将其转换为相应 ...

  3. android的ListView点击item使item展开的做法

    直接上代码把.主要是又一次给item measure高度,直接上代码把 import java.util.ArrayList; import android.app.Activity; import ...

  4. nyist oj 19 擅长排列的小明(dfs搜索+STL)

    擅长排列的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 小明十分聪明.并且十分擅长排列计算.比方给小明一个数字5,他能立马给出1-5按字典序的全排列,假设你想 ...

  5. 浅谈MySQL Capabilities --从调研PHP mysqlnd源码细节角度认识

    今天一起来研究下MySQL Capabilities,这个非常重要,如果大家有想法自己动手实现一个MySQL客户端或者Proxy工具,那么就得先了解一下这块,正好PHP 5.3以上版本由于官方为了规避 ...

  6. Write a program that gives count of common characters presented in an array of strings..(or array of

    转自出处 Write a program that gives count of common characters presented in an array of strings..(or arr ...

  7. Session管理之ThreadLocal

    ref=toolbar" target="_blank">ref=toolbar_logo" target="_blank"> ...

  8. Spring和SpringMVC的关系

    1.Spring和SpringMVC是父子容器关系. 2.Spring整体框架的核心思想是容器,用来管理bean的生命周期,而一个项目中会包含很多容器,并且它们分上下层关系,目前最常用的一个场景是在一 ...

  9. Java中的字节输入出流和字符输入输出流

    Java中的字节输入出流和字符输入输出流 以下哪个流类属于面向字符的输入流( ) A BufferedWriter B FileInputStream C ObjectInputStream D In ...

  10. J2SE基础:11.异常处理

    1:异常的概念: 异常是程序在执行时发生的事件(异常发生在执行期间). 程序出现错误.打断原本的运行流程. 2:Java中处理异常. 在Java中.异常被封装成一个对象.(属性和方法) 3:异常产生 ...