1656C - Make Equal With Mod - CodeForces Solution


math number theory sortings

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    c1 = 0
    for i in a:
        if i==1:
            c1+=1
            break
    if c1==0:
        print("yes")
        continue
    c = 0
    for i in range(n-1):
        if a[i+1] == a[i]+1:
            c+=1
            break
    if c>0:
        print("no")
        continue
    print("yes")

C++ Code:

/******Code******/
//    CODE BY A_K ;)

//		(⌐■_■)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define pop pop_back()
#define le(i,a,b) for(i=a;i<=b;++i)
#define de(j,a,b) for(j=a;j>=b;--j)
#define arsort(arr,n) sort(arr,arr+n)
#define rvarsort(arr,n) sort(arr,arr+n,greater<ll>())
#define vi vector<ll>
#define all(a) (a).begin(),(a).end()
#define vecsort(vec) sort(vec.begin(),vec.end())
#define Mod 10e9+7
ll md=Mod;
bool primes[1000001]; //For sieve
/*Ascii Values!!:
A=65,Z=90,a=97,z=122*/

//*****Arr-Input****
void takearr(ll arr[],ll n)
{
    for(ll i=0;i<n;i++)
        cin>>arr[i];
}

//********Sieve******
/*void sieve(){

    memset(primes, true, sizeof(primes));
    primes[1] = false; primes[0] = false;
    for(size_t i = 2; i*i <= Mod; i++){
        if(primes[i]){
            for(size_t j = i*i; j < Mod; j += i)
            primes[j] = false;
}}}*/

//******FACTORS*******
void allfacts(ll n, vector<ll> &v){
    for(ll i=1; i<=sqrt(n); ++i){
        if(n%i==0){
        if(n/i==i)
            v.push_back(i);
        else{
            v.push_back(i);
            v.push_back(n/i);
        }
}}}
bool checkarr(ll arr[],ll n)
{
    ll i;
    ll chk=arr[0];
    le(i,1,n-1)
    {
        if(arr[i]!=chk)
            return false;
    }
    return true;
}
//******SOLVER******
void solver(){
ll i,n,j,mod=Mod;
cin>>n;
bool one=0,zero=0;
ll arr[n];
le(i,0,n-1)
{
    cin>>arr[i];
    if(arr[i]==1)
        one=true;
    if(arr[i]==0)
        zero=true;
}
if(checkarr(arr,n))
{
    cout<<"YES\n";
    return;
}
if(one && zero){
    cout<<"NO\n"; return;
}
if(one)
{
    sort(arr,arr+n);
    //bool chk=false;
    le(i,1,n-1)
    {
        if(arr[i]-arr[i-1]==1){
           // chk=true;
           cout<<"NO\n";
           return;
        }
    }
    cout<<"YES\n";
    return;
}
cout<<"YES\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    cin>>t;
    while(t--)
        solver();
return 0;
}


Comments

Submit
0 Comments
More Questions

1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated