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

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<bits/stdc++.h>
using namespace std;

typedef unsigned long long LL;
#define MOD 1e9 + 7

const int maxn = 4 * 100000 + 10;

int _min(int a, int b) {
    if (a < b) return a;
    else return b;
}

int _max(int a, int b) {
    if (a > b) return a;
    else return b;
}

LL gcd(LL a, LL b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

LL p[maxn];


LL prime[maxn];
void getPrime() {
    memset(prime, 0, sizeof(prime));
    for (LL  i = 2; i <= maxn; i++) {
        if (!prime[i]) prime[++prime[0]] = i;
        for (LL j = 1; j <= prime[0] && prime[j] * i <= maxn; j++) {
            prime[prime[j] * i] = 1;
            if (i % prime[j] == 0) break;
        }
    }
}

int main() {
    LL n;
    getPrime();
    //printf("%d\n", prime[1]);
    cin >> n;
    for (LL i = 1; i <= n; i++) {
        LL a, b;
        cin >> a >> b;
        p[i] = b / gcd(a, b) * a;
    }
    LL g = p[1];
    for (LL i = 2; i <= n; i++) {
        g = gcd(g, p[i]);
    }
    for (LL i = 1; i < prime[0]; i++) {
        if (g % prime[i] == 0) {
            g = prime[i];
            break;
        }
    }
    if (g == 1) cout << "-1" << endl;
    else cout << g << endl;
    return 0;
}

 C,D : 不会待补。。。

EFG  : 再说吧<>

猜你喜欢

转载自www.cnblogs.com/mrh-acmer/p/9503271.html