Balanced Strings emo

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int is(char c) {
	if(c=='i'||c=='o'||c=='a'||c=='u'||c=='e'||c=='y')
		return 1;
	else 
		return 0;
}
int main()
{
	string s;
	ll l,sum=1,cnt=0,g=0,ji,f=1;
	cin>>s;
	l=s.size();
	for(int i=0;i<l&&f;i++)
	{
		if(!g&&s[i]=='?')
		{
			ji=i-1;
			g=1;
			cnt=0;
		}
		if(g&&s[i]=='?')
		{
			cnt++;
		}
		if(cnt&&i==l-1&&s[i]=='?')
		{
			if(ji<0)
			{
				for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=20;
					else sum*=6;
				}
				sum+=(sum/20)*6;
				cout<<sum;
				return 0;
			}
			
			if(cnt%2==0)
			{
				for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=20;
					else sum*=6;
				}
				cout<<sum;
				return 0;
			}
			if(cnt%2)
			{
				for(int j=1;j<cnt;j++)
				{
					if(j%2)sum*=20;
					else sum*=6;
				}
				if(is(s[ji]))sum*=20;
				else sum*=6;
				cout<<sum;
				return 0;
			}
		}
		
		if(is(s[i]))
		{
			if(i>0&&is(s[i-1])) 
			{
			
				f=0;break;
			}
			if(cnt)
			{
				if(cnt%2)
				{
					if(ji>=0&&(is(s[ji])+is(s[i])==1))
						{
							
						f=0;break;
					}
					for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=20;
					else sum*=6;
				}
				
				}
				else 
				{
					if(ji>=0&&(is(s[ji])+is(s[i])==2||is(s[ji])+is(s[i])==0))
						{
						
						f=0;break;
					}
					for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=6;
					else sum*=20;
				}
				}
			}
			g=0;cnt=0;
		}
		
		if(!is(s[i])&&s[i]!='?')
		{
			if(i>0&&!is(s[i-1])&&s[i-1]!='?') 
			{
				f=0;break;
			}
			if(cnt)
			{
				if(cnt%2)
				{
					if(ji>=0&&(is(s[ji])+is(s[i])==1))
						{
						f=0;break;
					}
					for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=6;
					else sum*=20;
				}
				}
				else 
				{
					if(ji>=0&&(is(s[ji])+is(s[i])==2||is(s[ji])+is(s[i])==0))
						{
						f=0;break;
					}
					for(int j=1;j<=cnt;j++)
				{
					if(j%2)sum*=6;
					else sum*=20;
				}
				}
			}
			g=0;cnt=0;
		}
	
	}
	if(!f)cout<<"0";
	else cout<<sum;
}

http://202.194.62.52/contest/1988

不看错误样例直接过不去
情况太多
极端情况想不到(都是?)
讨论的太多 先后顺序搞不清
最后终于过了
Description
Being an individual obsessed with balancing and trying to find strings that meet that criteria, you have begun a new endeavor to study the curious structure of what we will call balanced strings.

Balanced strings are strings that maintain an equal ratio of consonants to vowels in all of their substrings. What? You don’t know the difference between a consonant and a vowel? Vowels are the characters ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ and sometimes ‘y’. Actually, you don’t like the character ‘y’ because this makes the problem much harder. What was the difficulty level of this problem again? Oh yeah Medium! We can’t have a problem about consonants and vowels that makes ‘y’ sometimes a vowel! That would make the problem a Hard and too many hard problems is a very bad thing. Being obsessed with balance, you have decided that ‘y’ will be included with the vowels. That way, there are 6 vowels and 20 consonants. A nice balanced even number of both! Oh! I almost forgot! A consonant is any letter that is not a vowel. Also to simplify things (this is a Medium problem after all!), we will consider strings composed of lowercase letters only.

Now you are ready to understand balanced strings! A balanced string is a string that has an equal number of consonants and vowels in all of its substrings. Well… not all of its substrings. Just the substrings of even length! For example, the string “orooji” has the following set of evenlength substrings: {“or”, “ro”, “oo”, “oj”, “ji”, “oroo”, “rooj”, “ooji”, “orooji”}. In that set the following substrings are unbalanced: {“oo”, “oroo”, “ooji”, “orooji”}. That is, the substrings do not contain an equal number of vowels and consonants. So, the string “orooji” is not balanced. But a string like “arup” is balanced. The requisite even-length substrings are: {“ar”, “ru”, “up”, “arup”} and all these substrings are balanced (have the same number of vowels and consonants), thus the string “arup” is balanced. Note that a balanced string may contain an odd number of characters, e.g., the string “ali” is balanced since all its even-length substrings ({“al”, “li”}) are balanced.

Now you want to take words and erase some of the letters and replace them with new letters to form balanced strings. Since this is a Medium problem, we’ve taken the liberty of erasing some of the letters for you and replaced them with ‘?’ characters. See! The problem is already halfway solved!

Given a string of lowercase letters and ‘?’ characters, count the number of ways to replace all the ‘?’ with lowercase letters such that the string results in a balanced string. Two ways are considered different if there exists some i such that the ith character in one string differs from the ith character of the other string. Note that all the ‘?’ do not have to be replaced by the same letter.

Input
There is one input line, it contains a string. The string contains only lowercase letters and/or ‘?’ characters. Assume the input string has at least one character and at most 100 characters.

Output
Print the number of ways to replace the question marks with lower case letters such that the string results in a balanced string. It is guaranteed that the output value will fit in a signed 64-bit integer for the string we provide.

Samples
Input 复制
orooji
Output
0
Input 复制
al?
Output
6
Input 复制
a?i
Output
20
Input 复制
g?ha
Output
6
Input 复制
a?u?
Output
400
Input 复制
???
Output
1117952409600000000
Input 复制
arup
Output
1
Hint
Note: The first Sample Input and the last Sample Input do not have any ‘?’. The first string is not balanced so there is no way of replacing all ‘?’ to make it balanced, thus the output is zero. However, the last string is balanced so there is one way of replacing all ‘?’ to make it balanced, thus the output is 1.

Source
UCF 2021 Practice

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值