zoukankan      html  css  js  c++  java
  • AtCoder Regular Contest 081 E

    E - Don't Be a Subsequence


    Time limit : 2sec / Memory limit : 256MB

    Score : 600 points

    Problem Statement

    A subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters. For example, arcartistic and (an empty string) are all subsequences of artisticabc and ci are not.

    You are given a string A consisting of lowercase English letters. Find the shortest string among the strings consisting of lowercase English letters that are not subsequences of A. If there are more than one such string, find the lexicographically smallest one among them.

    Constraints

    • 1≤|A|≤2×105
    • A consists of lowercase English letters.

    Input

    Input is given from Standard Input in the following format:

    A
    

    Output

    Print the lexicographically smallest string among the shortest strings consisting of lowercase English letters that are not subsequences of A.


    Sample Input 1

    Copy
    atcoderregularcontest
    

    Sample Output 1

    Copy
    b
    

    The string atcoderregularcontest contains a as a subsequence, but not b.


    Sample Input 2

    Copy
    abcdefghijklmnopqrstuvwxyz
    

    Sample Output 2

    Copy
    aa
    

    Sample Input 3

    Copy
    frqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfniuyskxiyjpjlxuqnfgmnjcvtlpnclfkpervxmdbvrbrdn
    

    Sample Output 3

    Copy
    aca


    dp[i]代表[i~n]的子串的最小字典序串的长度
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<map>
    #include<cmath>
    #include<set>
    #include<stack>
    #define ll long long
    #define pb push_back
    #define max(x,y) ((x)>(y)?(x):(y))
    #define min(x,y) ((x)>(y)?(y):(x))
    #define cls(name,x) memset(name,x,sizeof(name))
    #define fs first
    #define sc second
    #define mp make_pair
    #define L(x) (1<<x)
    #define next Next
    using namespace std;
    const int inf=1e9+10;
    const ll llinf=1e16+10;
    const int maxn=2e5+10;
    const int maxm=1e3+10;
    const int mod=1e9+7;
    int n;
    vector<int> v[30];
    char s[maxn];
    int dp[maxn];
    int nch=26;
    int querry(int pos,int ch)
    {
        vector<int>::iterator it;
        it=lower_bound(v[ch].begin(),v[ch].end(),pos);
        if(it==v[ch].end()) return n;
        else return *it;
    }
    void solve()
    {
        dp[n+1]=0;
        for(int i=n-1;i>=0;i--)
        {
            for(int j=0;j<nch;j++)
                dp[i]=min(dp[i],dp[querry(i,j)+1]+1);
        }
        int pos=0;
        while(pos<n)
        {
            for(int j=0;j<nch;j++)
            {
                int t=querry(pos,j)+1;
                if(dp[pos]==dp[t]+1)
                {
                    printf("%c",j+'a');
                    pos=t;
                    break;
                }
            }
        }
        printf("
    ");
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(~scanf("%s",s))
        {
            for(int i=0;i<nch;i++)
                v[i].clear();
            n=strlen(s);
            for(int i=0;i<=n;i++)
                dp[i]=inf;
            for(int i=0;i<n;i++)
                v[s[i]-'a'].pb(i);
            solve();
        }
        return 0;
    }
  • 相关阅读:
    ARM学习笔记10——GNU ARM命令行工具
    ARM学习笔记9——ARM汇编汇编语言中的伪指令
    ARM学习笔记8——通用寄存器和存储器内容交换指令和软中断指令
    ARM学习笔记7——乘法指令
    ARM学习笔记6——程序状态寄存器访问指令
    ARM学习笔记5——程序状态寄存器
    ARM学习笔记4——加载存储指令
    ARM学习笔记3——数据处理指令
    ARM学习笔记2——分支跳转指令
    ARM学习笔记1——Arm寄存器与模式的关系
  • 原文地址:https://www.cnblogs.com/mgz-/p/7419263.html
Copyright © 2011-2022 走看看