1836A - Destroyer - CodeForces Solution


sortings

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define py cout << "yes" << endl
#define pn cout << "no" << endl
#define pm cout << "-1" << endl
#define minheapp priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
#define maxheapp priority_queue<pair<ll, ll>>
#define minheap priority_queue<ll, vector<ll>, greater<ll>>
#define maxheap priority_queue<ll>
ll mod = 1e9 + 7;
ll gcd(ll a, ll b)
{
    return __gcd(a, b);
}
ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}
void pv(vector<ll> v)
{
    for (auto i : v)
    {
        cout << i << " ";
    }
    cout << endl;
}
// ll n; cin>>n; vector<ll>v(n); for(ll i =0; i<n; i++) {cin>>v[i];}
void solve()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    map<ll, ll> m;
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
        m[v[i]]++;
    }
    sort(all(v));
    ll prev = n+1;
    for (ll i = 0; i <= v.back(); i++)
    {
        if (m[i] == 0 || m[i]>prev)
        {
            pn;
            return;
        }
        prev = m[i];
    }
    py;
}
int main()

{
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


Comments

Submit
0 Comments
More Questions

952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word