1798B - Three Sevens - CodeForces Solution


implementation

Please click on ads to support us..

C++ Code:

//Not the Best :)

#include <bits/stdc++.h>
using namespace std;

//DataTypes
using str =  string;
using ll  = long long;
using ld  = long double;
using vl  = vector<ll>;
using vd  = vector<ld>;
using vs  = vector<str>;
using vpl = vector<pair<ll,ll>>;
#define umap unordered_map
#define uset unordered_set

//Shorts
#define pus     push_back
#define pub     pop_back
#define ff       first
#define ss       second
#define dbg(x) cout<<#x<<" = "<<x<<'\n';

//Algorithms
#define sz(x)     ((ll)(x).size())
#define all(x)    x.begin(),x.end()
#define srt(x)    sort(all(x))
#define srtd(x)   sort(x.rbegin(),x.rend())
#define rev(x)    reverse(all(x));
#define Vmax(x)   *max_element(all(x))
#define Vmin(x)   *min_element(all(x))
#define Vsum(x)   accumulate(all(x),0ll)
#define lowB(v,x) *lower_bound(all(v),x) // >=x
#define upB(v,x)  upper_bound(all(v),x)-v.begin() // > x
#define ers(v,i)  v.erase(v.begin()+i) 
#define uniq(x)   x.erase(unique(all(x)),x.end())
#define NextP(x)  next_permutation(all(x))
#define PrevP(x)  prev_permutation(all(x))
#define cntB(x)   __builtin_popcountll(x)  
#define cntC(s,x) ll(count(all(s), x));

//loops
#define For(n)  for (ll i = 0; i < n; i++)
#define ForR(n) for (ll i = n-1; i >= 0; i--)
#define Forj(n) for (ll j = 0; j < n; j++)
#define For1(n) for (ll i = 1; i < n; i++)

//IO
#define nl      cout << "\n";
#define ya      cout << "YES\n";
#define na      cout << "NO\n";
#define inpt(v) For(sz(v)) cin >> v[i];
#define prt(v)  for(auto i:v) cout << i << " "; cout << "\n";

//Constants
const int M = 1e9+7; 
const int N = 2e5+5;
const ld pi = 3.141592653589793238;
const ll INF = 9e18;

ll n, a, b, c, k, m, x, y, q; str s;
 
//---------------------------------------------------------------------------------------------------------------------------------
//Let's Go :)

void solve()
{
    cin>>n;
    vl v(n);
    vl v3;
    map<ll,ll> mp1, mp2;
    vl vv[n];

    For(n){
        cin>>v[i];

        Forj(v[i]){
            cin>>x;
            vv[i].pus(x);
            mp1[x]++;
        }
    }
    

    For(n){
        k=0;
        Forj(vv[i].size()){
            mp2[vv[i][j]]++;
            if (mp1[vv[i][j]]==mp2[vv[i][j]] and k==0){ k=1; v3.pus(vv[i][j]);}
        }
        if (k==0){ cout<<-1; nl; return;}
    }
    prt(v3);


}

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


Comments

Submit
0 Comments
More Questions

345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array