Codeforces Round #537 (Div. 2)

A. Superhero Transformation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name ss can transform to another superhero with name tt if ss can be made equal to tt by changing any vowel in ss to any other vowel and any consonant in ss to any other consonant. Multiple changes can be made.

In this problem, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants.

Given the names of two superheroes, determine if the superhero with name ss can be transformed to the Superhero with name tt.

Input

The first line contains the string ss having length between 11 and 10001000, inclusive.

The second line contains the string tt having length between 11 and 10001000, inclusive.

Both strings ss and tt are guaranteed to be different and consist of lowercase English letters only.

Output

Output "Yes" (without quotes) if the superhero with name ss can be transformed to the superhero with name tt and "No" (without quotes) otherwise.

You can print each letter in any case (upper or lower).

Examples

input

Copy

a
u

output

Copy

Yes

input

Copy

abc
ukm

output

Copy

Yes

input

Copy

akm
ua

output

Copy

No

Note

In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string ss to tt.

In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string ss to tt.

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char s1[N],s2[N];
char a[10]={'a','o','e','i','u'};
int vis[30];
int main()
{
	cin>>s1>>s2;
	int len1=strlen(s1),len2=strlen(s2);
	for(int i=0;i<5;i++)
	{
		vis[a[i]-'a']=1;
	}
	if(len1!=len2)
	{
		printf("NO");
		return 0;
	}
	for(int i=0;i<len1;i++)
	{
		if(vis[s1[i]-'a']==1&&vis[s2[i]-'a']==1)
		{
			continue;
		}
		else if(vis[s1[i]-'a']==0&&vis[s2[i]-'a']==0)
		{
			continue;
		}
		else
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}

B. Average Superhero Gang Power

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations.

Initially, there are nn superheroes in avengers team having powers a1,a2,…,ana1,a2,…,an, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by 11. They can do at most mm operations. Also, on a particular superhero at most kk operations can be done.

Can you help the avengers team to maximize the average power of their crew?

Input

The first line contains three integers nn, kk and mm (1≤n≤1051≤n≤105, 1≤k≤1051≤k≤105, 1≤m≤1071≤m≤107) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — the initial powers of the superheroes in the cast of avengers.

Output

Output a single number — the maximum final average power.

Your answer is considered correct if its absolute or relative error does not exceed 10−610−6.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−6|a−b|max(1,|b|)≤10−6.

Examples

input

Copy

2 4 6
4 7

output

Copy

11.00000000000000000000

input

Copy

4 2 6
1 3 2 3

output

Copy

5.00000000000000000000

Note

In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times.

In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by 22 each.

没注意删除一个也是要消耗步数,搞得一直wa

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const double esp=1e-6; 
double a[N];
int n,m,k;
double ans;
int main()
{
	cin>>n>>k>>m;
	double sum=0;
	int num=0;
	for(int i=1;i<=n;i++) 
	{
		scanf("%lf",&a[i]);
		sum+=a[i];
		num++;
	}
	sort(a+1,a+1+n);
	double ans=(sum+1.0*min(n*k,m))/num;
	for(int i=1;i<n;i++)
	{
		sum-=a[i];
		int op=m-i;
		if(op<0) break;
		num--;
		ans=max(ans,(sum+min((double)op,(double)num*k))/(double)num);
	}
	printf("%.7lf\n",ans);
}
/*
9 2 8
74578 2746 96295 86884 21198 28655 22503 7868 47942

96295
*/

C. Creative Snap

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.

Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 22. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:

  • if the current length is at least 22, divide the base into 22 equal halves and destroy them separately, or
  • burn the current base. If it contains no avenger in it, it takes AA amount of power, otherwise it takes his B⋅na⋅lB⋅na⋅l amount of power, where nana is the number of avengers and ll is the length of the current base.

Output the minimum power needed by Thanos to destroy the avengers' base.

Input

The first line contains four integers nn, kk, AA and BB (1≤n≤301≤n≤30, 1≤k≤1051≤k≤105, 1≤A,B≤1041≤A,B≤104), where 2n2n is the length of the base, kkis the number of avengers and AA and BB are the constants explained in the question.

The second line contains kk integers a1,a2,a3,…,aka1,a2,a3,…,ak (1≤ai≤2n1≤ai≤2n), where aiai represents the position of avenger in the base.

Output

Output one integer — the minimum power needed to destroy the avengers base.

Examples

input

Copy

2 2 1 2
1 3

output

Copy

6

input

Copy

3 2 1 2
1 7

output

Copy

8

Note

Consider the first example.

One option for Thanos is to burn the whole base 1−41−4 with power 2⋅2⋅4=162⋅2⋅4=16.

Otherwise he can divide the base into two parts 1−21−2 and 3−43−4.

For base 1−21−2, he can either burn it with power 2⋅1⋅2=42⋅1⋅2=4 or divide it into 22 parts 1−11−1 and 2−22−2.

For base 1−11−1, he can burn it with power 2⋅1⋅1=22⋅1⋅1=2. For 2−22−2, he can destroy it with power 11, as there are no avengers. So, the total power for destroying 1−21−2 is 2+1=32+1=3, which is less than 44.

Similarly, he needs 33 power to destroy 3−43−4. The total minimum power needed is 66.

这题我觉得有点问题吧。

这是别人的说法,终重点在于  “不一定有连续的一段无人看守位置就一定一次使用A灭掉”,然后并不是,必须是 “一定有连续的一段无人看守位置就一定一次使用A灭掉”,否则就超时,亲身经历过。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll powmod(ll a,ll b) {ll res=1; assert(b>=0); 
for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
const int N=1e5+10;
int a[N];
int n,k;
ll x,y;
ll sum;
int f1,f2;
ll build(int l,int r)
{
	if(l==r)
	{
		ll ans=0;
		int id1=upper_bound(a+1,a+1+k,r)-a-1;
		int id2=upper_bound(a+1,a+1+k,l-1)-a-1;
		int num=id1-id2;
		if(num)	ans=num*y;
		else ans=x;
		return ans;
	}
	int id1=upper_bound(a+1,a+1+k,r)-a-1;
	int id2=upper_bound(a+1,a+1+k,l-1)-a-1;
	int num=id1-id2;
	if(num==0) return x; 
	
	int mid=l+r>>1;
	ll a1,a2,ans=0;
	ans=1ll*num*y*(r-l+1);
	a1=build(l,mid);
	a2=build(mid+1,r);
	return min(ans,a1+a2);

}
int main()
{
	cin>>n>>k>>x>>y;
	for(int i=1;i<=k;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+k);
	int l=1,r=powmod(2,n);
	printf("%lld\n",build(l,r));
}

猜你喜欢

转载自blog.csdn.net/qq_41286356/article/details/88847073