当前位置: 首页 > 工具软件 > doggo > 使用案例 >

Codeforces Round #505 A. Doggo Recoloring

赵雪峰
2023-12-01

原文地址:http://codeforces.com/contest/1025/problem/A

Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.

The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.

Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color xxsuch that there are currently at least two puppies of color xx and recolor all puppies of the color xx into some arbitrary color yy. Luckily, this operation can be applied multiple times (including zero).

For example, if the number of puppies is 77 and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose xx='c' right now, because currently only one puppy has the color 'c'.

Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of puppies.

The second line contains a string ss of length nn consisting of lowercase Latin letters, where the ii-th symbol denotes the ii-th puppy's color.

Output

If it's possible to recolor all puppies into one color, print "Yes".

Otherwise print "No".

Output the answer without quotation signs.

Examples

input

Copy

6
aabddc

output

Copy

Yes

input

Copy

3
abc

output

Copy

No

input

Copy

3
jjj

output

Copy

Yes

Note

In the first example Slava can perform the following steps:

  1. take all puppies of color 'a' (a total of two) and recolor them into 'b';
  2. take all puppies of color 'd' (a total of two) and recolor them into 'c';
  3. take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.

In the second example it's impossible to recolor any of the puppies.

In the third example all the puppies' colors are the same; thus there's no need to recolor anything.

 

题意:给出n位由a到z的小写字母组成的字符串,判断此字符串是否可以通过每次至少改变两个相同的字符,最后实现全部字符相同。

思路:我是用一个数组在输入时把每个字符出现的次数存到数组里,然后对数组进行降序排序,如果最后数组第一个值大于等于2,就输出yes,此处需要注意,当输入只有一个字符时,要另加一个判断。

下面时AC代码

#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int Max=1e5+1;
int a[Max];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    cin>>n;
    char x;
    memset(a,0,sizeof(a));
    for(int i=0; i<n; i++)
    {
        cin>>x;
        a[int(x)]++;
    }
    sort(a,a+200,cmp);
    if(a[0]>=2)
        cout<<"Yes"<<endl;
    else if(a[0]==1&&a[1]==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

 

 类似资料:

相关阅读

相关文章

相关问答