2019CCPC湖南全国邀请赛(广东省赛、江苏省赛) E Hello xtCpc

Problem Description

You have a string of lowercase letters.You need to find as many sequence “gdCpc” as possible.But letters in the same position can only be used once。

 

 

Input

The input file contains two lines.

The first line is an integer n show the length of string.(1≤n≤2×105)

The second line is a string of length n consisting of lowercase letters and uppercase letters.

 

 

Output

The input file contains an integer show the maximum number of different subsequences found.

 

 

Sample Input


 

10 gdCgdCpcpc

 

 

Sample Output


 

2

 思路:前缀和,分成 c,xt,xtC,xtCp,xtCpc

#include<cstdio>
#include<cstring>
using namespace std;
char a[205000];
int falg=1;//xtCpc

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",a);
        /*for(int i=0;i<40000;i++) a[i]='x';
        for(int i=40000;i<80000;i++) a[i]='t';
        for(int i=80000;i<120000;i++) a[i]='C';
        for(int i=120000;i<160000;i++) a[i]='p';
        for(int i=160000;i<200000;i++) a[i]='c';
        a[200000]='\0';*/
        int sum[10]={0},s=0;
        for(int i=0;a[i]!='\0';i++)
        {
            if(a[i]=='x') sum[1]++;
            else if(a[i]=='t')
            {
                if(sum[1]>=1)
                {
                    sum[1]--;
                    sum[2]++;
                }
            }
            else if(a[i]=='C') {
                if(sum[2]>=1)
                {
                    sum[2]--;
                    sum[3]++;
                }
            }
            else if(a[i]=='p') {
                if(sum[3]>=1)
                {
                    sum[3]--;
                    sum[4]++;
                }
            }
            else if(a[i]=='c')
            {
                if(sum[4]>=1)
                {
                    sum[4]--;
                    sum[5]++;
                }
            }
        }
        //scanf("%s",a);
        printf("%d\n",sum[5]);
    }
}

 

全部评论

相关推荐

站队站对牛:进度也算很慢的了
点赞 评论 收藏
分享
鱼专:别投了,我看到有人点了第二个链接投递,还没退出界面,不合适的邮件就发过来了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务