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不是没有道理的……


  • 相关阅读:
    【SR汇总】基于传统方法
    漫展被骗
    SRCNN代码分析
    【SR汇总】效果对比
    【SR汇总】算法时间效率
    根据wsdl文件,Java工程自动生成webservice客户端调用
    Python3 Selenium WebDriver网页的前进、后退、刷新、最大化、获取窗口位置、设置窗口大小、获取页面title、获取网页源码、获取Url等基本操作
    Python3 Selenium自动化-select下拉框
    Python3 ChromeDriver与Chrome版本映射表(更新至v2.43)
    Python3 Selenium自动化测试赋值出现:WebDriverException: Message: unknown error: call function result missing 'value'
  • 原文地址:https://www.cnblogs.com/dilthey/p/6804170.html
Copyright © 2011-2022 走看看