zoukankan      html  css  js  c++  java
  • Codeforces 779D

    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    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 ta1... 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.

    Input

    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).

    Output

    Print a single integer number, the maximum number of letters that Nastya can remove.

    Examples
    input
    ababcba
    abb
    5 3 4 1 7 6 2
    
    output
    3
    input
    bbbabb
    bb
    1 6 3 4 2 5
    
    output
    4
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 using namespace std;
     5 int a[200000+5];
     6 char temp[200000+5];
     7 bool check(const char t[],const char p[],int mid)
     8 {
     9     memset(temp,0,sizeof(temp));
    10     strcpy(temp,t); //拷贝到一个临时数组 
    11     for(int i=1;i<=mid;i++) temp[a[i]-1]='0'; //把要划掉的那几个字母依次划掉
    12     for(int i=0,j=0,temp_len=strlen(t),p_len=strlen(p);i<temp_len;i++){
    13         if(temp[i] == p[j]) j++;
    14         if(j == p_len) return true;
    15     } 
    16     return false;
    17 }
    18 int main()
    19 {
    20     char t[200000+5],p[200000+5];
    21     scanf("%s%s",t,p);
    22     int t_len=strlen(t);
    23     for(int i=1;i<=t_len;i++) scanf("%d",&a[i]);
    24     int st=0,ed=t_len;
    25     while(ed-st>1)
    26     {
    27         int mid=st+(ed-st)/2;
    28         if(check(t,p,mid)) st=mid;
    29         else ed=mid;
    30     }
    31     printf("%d
    ",st);
    32 }

    开始的时候一直在test 10上RUNTIME_ERROR,一直找不出原因,刚开始以为二分那边有问题,换了网上AC的二分方式依然是这样,后来才发现开int数组a[]的大小时候

    200000+5写成了20000+5……真是僵硬……看来预定义一个MAXN不是没有道理的……


  • 相关阅读:
    实验五 shell脚本编程
    实验四 Linux系统C语言开发环境学习
    实验三 Linux系统用户管理及VIM配置
    实验二 Linux系统简单文件操作命令
    实验一 Linux系统与应用准备
    实验八 进程间通信
    实验七 信号
    实验六 进程基础
    实验五 shell脚本编程
    实验四 Linux系统搭建C语言编程环境
  • 原文地址:https://www.cnblogs.com/dilthey/p/6804170.html
Copyright © 2011-2022 走看看