Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

筅森魡賤 提交于 2020-05-09 12:23:04

A :

A. Doggo Recoloring
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 x

such that there are currently at least two puppies of color x and recolor all puppies of the color x into some arbitrary color y

. Luckily, this operation can be applied multiple times (including zero).

For example, if the number of puppies is 7

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 x

='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 n

(1n105

) — the number of puppies.

The second line contains a string s

of length n consisting of lowercase Latin letters, where the i-th symbol denotes the i

-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.

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
typedef long long ll;
const double PI = acos(-1.0);
const int INF = 1000000000;
const int maxn = 10005;

void Debug()
{
    puts("");
    cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
    for(int i=0; i<1; i++)
    {
        for(int j=0; j<1; j++)
        {
            cout<<13221321321312321<<" ";
        }
        cout<<endl;
    }
    cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
    puts("");
}
int vis[100005];

char f[100005];

int flag = 0;

int main ()
{
    int n;scanf ("%d" , &n);scanf ("%s" , &f);
    if (n == 1){printf ("YES\n");return 0;}
    for (int i = 0 ; i < n ; i++){int h = f[i] - 'a';vis[h]++;if (vis[h] >= 2){
            flag++;
            break;
        }
    }if (flag) printf ("YES\n");
    else printf ("NO\n");
}

 

 

B:

B. Weakened Common Divisor
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.

For a given list of pairs of integers (a1,b1)

, (a2,b2), ..., (an,bn) their WCD is arbitrary integer greater than 1

, such that it divides at least one element in each pair. WCD may not exist for some lists.

For example, if the list looks like [(12,15),(25,18),(10,24)]

, then their WCD can be equal to 2, 3, 5 or 6 (each of these numbers is strictly greater than 1

and divides at least one number in each pair).

You're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate WCD efficiently.

Input

The first line contains a single integer n

(1n150000

) — the number of pairs.

Each of the next n

lines contains two integer values ai, bi (2ai,bi2109

).

Output

Print a single integer — the WCD of the set of pairs.

If there are multiple possible answers, output any; if there is no answer, print 1

.

Examples
Input
Copy
3
17 18
15 24
12 15
Output
Copy
6
Input
Copy
2
10 16
7 17
Output
Copy
-1
Input
Copy
5
90 108
45 105
75 40
165 175
33 30
Output
Copy
5
Note

In the first example the answer is 6

from the third ones. Note that other valid answers will also be accepted.

In the second example there are no integers greater than 1

satisfying the conditions.

In the third example one of the possible answers is 5

开始想复杂勒, 其实只要求出每行两个数的最小公倍数,再求所有最小公倍数的最大公因数,判断是否为1;

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define LL long long
#define mk(a,b) make_pair(a,b)
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
LL a[200010][2];
inline LL gcd(LL x,LL y){
    return y?gcd(y,x%y):x;
}
int main(){
    int n;
    scanf("%d",&n);
    LL sum=0,ans=0;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i][0],&a[i][1]);
        sum=gcd(a[i][0]*a[i][1],sum);
    }
    if(sum==1){
        printf("-1\n");
        return 0;
    }
    for(int i=2;i*i<=a[1][0];i++){
        if(ans==0&&sum%i==0)ans=i;
        while(a[1][0]%i==0)a[1][0]/=i;
    }
    if(ans==0&&a[1][0]>1&&sum%a[1][0]==0)ans=a[1][0];
    for(int i=2;i*i<=a[1][1];i++){
        if(ans==0&&sum%i==0)ans=i;
        while(a[1][1]%i==0)a[1][1]/=i;
    }
    if(ans==0&&a[1][1]>1&&sum%a[1][1]==0)ans=a[1][1];
    printf("%lld\n",ans);
}

 

 C,D : 不会待补。。。

 

EFG  : 再说吧<>

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!