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

(1≤n≤105

) — 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

6aabddc

Output

Copy

Yes

Input

Copy

3abc

Output

Copy

No

Input

Copy

3jjj

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

(1≤n≤150000

) — the number of pairs.

Each of the next n

lines contains two integer values ai, bi (2≤ai,bi≤2⋅109

).

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

317 1815 2412 15

Output

Copy

6

Input

Copy

210 167 17

Output

Copy

-1

Input

Copy

590 10845 10575 40165 17533 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  : 再说吧<>

原文地址:https://www.cnblogs.com/mrh-acmer/p/9503271.html

时间: 2024-08-30 05:50:31

Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)的相关文章

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching B. Pair of Toys C. Bracket Subsequence D. Array Restoration-区间查询最值(RMQ(ST))

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching 题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * ". 1 //A 2 #include<iostream> 3 #include<cstdio&g

Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)

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 mat

【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor

[链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. 显然用这些质因子去试2..n就可以了. 看哪个可以满足 就输出对应的就可以了. (一开始我求出这个数的所有因子(TLE了)..其实没有必要...因为假设y是x的倍数..然后y满足的话,显然x也能满足要求..所以只要用质因子搞就行了. [代码] #include <bits/stdc++.h> #

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

真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性质不难发现 我在30分钟的时候通过了pretest 但是由于自己的愚蠢 忘记写了一句话 导致FST了... D本来是一个简单的dp题 但是我一直没往dp上想 在网络流上刚了1h之后终于换了思路 在1:45的时候通过了他 然后就时间不多了 E都没看 就去hack 成功hack了2个之后比赛就结束了 题

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

考场上只做出了ABDE C都挂了... 题解: A 题解: 模拟 判断前面一段是否相同,后面一段是否相同,长度是否够(不能有重叠) Code: 1 #include<stdio.h> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<vector> 6 #include<map> 7 #include<set> 8 #inclu

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) D. Array Restoration

D. Array Restoration time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Initially there was an array aa consisting of nn integers. Positions in it are numbered from 11 to nn. Exactly qq querie

codeforces cf round#505(based on vk cup 2018 final) C. Plasticine zebra

构造题,把整个串想象成一个环.每次把环断开并反转的时候从切口处看进去的顺序是和刚开始从头到尾的顺序是一样的.于是每次不管如何翻转最后都要找到这个环上最大的连续子段长度 #include<bits/stdc++.h> using namespace std; string s; int main() { cin>>s; int tmp=s.size(); s=s+s; int ans=0; int len=1; for(int i=0;i<(int)s.size()-1;i++

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记

题目链接:C. Producing Snow 题意:给两个数组v[N],T[N],v[i]表示第i天造的雪,T[i],表示第i天的温度,一堆雪如果<=T[i],当天就会融完,否则融化T[i],要求输出每天的融雪总量. 题解:我对T数组求个前缀和,就可以二分找到每堆雪在那一天(pos)融化,余下的要加进答案中ans[i],然后用一个an数组在a[i]+1,a[pos]-1,最后求再求一次前缀和. ans[i]再加上an[i]*t[i].每次操作二分logn,N次操作.复杂度O(nlogn) #in

Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)

A. Tritonic Iridescence 题解:分类讨论.注意题目要求,至少有两种方案. 1 #pragma warning(disable:4996) 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 9 int n, m; 10 stri