codeforces 779D - String Game
2 seconds
512 megabytes
standard input
standard output
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"
"nastya"
"nastya"
"nastya"
"nastya"
"nastya"
"nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word p can be obtained by removing the letters from word t.
The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.
Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).
Print a single integer number, the maximum number of letters that Nastya can remove.
ababcba
abb
5 3 4 1 7 6 2
3
bbbabb
bb
1 6 3 4 2 5
4
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int a[+];
char temp[+];
bool check(const char t[],const char p[],int mid)
{
memset(temp,,sizeof(temp));
strcpy(temp,t); //拷贝到一个临时数组
for(int i=;i<=mid;i++) temp[a[i]-]=''; //把要划掉的那几个字母依次划掉
for(int i=,j=,temp_len=strlen(t),p_len=strlen(p);i<temp_len;i++){
if(temp[i] == p[j]) j++;
if(j == p_len) return true;
}
return false;
}
int main()
{
char t[+],p[+];
scanf("%s%s",t,p);
int t_len=strlen(t);
for(int i=;i<=t_len;i++) scanf("%d",&a[i]);
int st=,ed=t_len;
while(ed-st>)
{
int mid=st+(ed-st)/;
if(check(t,p,mid)) st=mid;
else ed=mid;
}
printf("%d\n",st);
}
开始的时候一直在test 10上RUNTIME_ERROR,一直找不出原因,刚开始以为二分那边有问题,换了网上AC的二分方式依然是这样,后来才发现开int数组a[]的大小时候
200000+5写成了20000+5……真是僵硬……看来预定义一个MAXN不是没有道理的……
codeforces 779D - String Game的更多相关文章
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
- CodeForces - 779D String Game 常规二分
题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...
- CodeForces - 779D String Game(二分)
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...
- 【codeforces 779D】String Game
[题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个 ...
- Codeforces 799D. String Game 二分
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...
- 779D. String Game 二分 水
Link 题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串 思路: 限制低,直接二分答案,即二分序列位置,不断check即可. ...
- Codeforces - 828C String Reconstruction —— 并查集find()函数
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seco ...
- CodeForces 159c String Manipulation 1.0
String Manipulation 1.0 Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on Cod ...
- Codeforces 710F String Set Quries
题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...
随机推荐
- IOS端的摇一摇功能
//微信的摇一摇是怎么实现的~发现原来 ios本身就支持 //在 UIResponder中存在这么一套方法 - (void)motionBegan:(UIEventSubtype)motion wit ...
- Android重写HorizontalScrollView仿ViewPager效果
Android提供的ViewPager类太复杂,有时候没有必要使用,所以重写一个HorizontalScrollView来实现类似的效果,也可以当做Gallery来用 思路很简单,就是重写onTouc ...
- Ubuntu 16.04服务器 软件的安装及配置
SSH的安装及配置 SSH分客户端openssh-client和openssh-server 如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有则 ...
- logback -- 配置详解 -- 二 -- <appender>
附: logback.xml实例 logback -- 配置详解 -- 一 -- <configuration>及子节点 logback -- 配置详解 -- 二 -- <appen ...
- Git Step by Step – (1) Git 简介
由于工作的需要,代码版本控制工具要从Perforce换成Git.说实话,刚开始真的很不适应,要从一个可以很好的支持用户界面的工具转到一个命令行工具,而且Git中有几百个命令,一下子就傻眼了. 但是经过 ...
- php大数除法保留精度问题
有人在群里问大数除法,要求保留精度的问题,发现普通的方法都不能保存精度,最后找了一下资料发现可以这样 这倒是个冷门知识,嗯哼
- PowerDesigner导出word,PowerDesigner把表导出到word,PDM导出word文档
PowerDesigner导出word,PowerDesigner把表导出到word,PDM导出word文档 >>>>>>>>>>>& ...
- 文件名过滤器FilenameFilter的用法
Java.io.FilenameFilter是文件名过滤器,用来过滤不符合规格的文件名,并返回合格的文件: 实例1,匹配指定字符结尾的文件 package cn.test; import java.i ...
- 嵌入式之UBOOT
嵌入式Linux系统的结构分为四个区,如图所示: 1.Bootloader区存放的是Bootloader,Coidre972开发板上使用的uboot,它负责嵌入式系统最初的硬件初始化.驱动和内核加载. ...
- Windows虚拟地址转物理地址(原理+源码实现,附简单小工具)
...