887B - Cubes for Masha - CodeForces Solution


brute force implementation *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll             long long
#define int            ll
#define pb             push_back
#define ld             long double
#define lala           for(ll i=0;i<n;i++)
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
using namespace std;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void vin( vector<int> &v , int n ){for (int i = 0; i < n; i++){int x ;cin >> x; v.push_back(x);}}
void vout(vector<int> &v){for (int i = 0; i < v.size(); i++){cout << v[i] << " " ;}cout << endl;}
long long lcm(int a, int b){    return (a / gcd(a, b)) * b;}
int digits_count(int n){int d=0;while(n != 0){d++;n /=10;}return d;}



void hello()
{
    int n;
    cin>>n;
    if(n==1)
    {
        vi a;
        vin(a,6);
        sort(a.begin(),a.end());
        int j=1;
        // vout(a);
        for(auto i:a)
        {
            // cout<<i<<endl;
            if(i==0)
            continue;
            else if(j!=i)
            {
                cout<<j-1<<endl;
                return ;
            }
            j++;
        }
        cout<<j-1<<endl;
    }
    else if(n==2)
    {
        vi a,b;
        vin(a,6);
        vin(b,6);
        // vin(c,6);
        set<int>s;
        for(auto i:a)
        {
            for(auto j:b)
            {
                
                s.insert(i);
                s.insert(j);
                s.insert(i*10+j);
                s.insert(j*10+i);
                
            }
        }
        int j=1;
        for(auto i:s)
        {
            if(i==0)
            continue;
            else if(j!=i)
            {
                cout<<j-1<<endl;
                return ;
            }
            j++;
        }
        cout<<j-1<<endl;
    }
    else 
    {
        vi a,b,c;
        vin(a,6);
        vin(b,6);
        vin(c,6);
        set<int>s;
        for(auto i:a)
        {
            for(auto j:b)
            {
                for(auto k:c)
                {
                    s.insert(i);
                    s.insert(j);
                    s.insert(k);
                    s.insert(i*10+j);
                    s.insert(j*10+i);
                    s.insert(i*10+k);
                    s.insert(k*10+i);
                    s.insert(j*10+k);
                    s.insert(k*10+j);
                }
            }
        }
        int j=1;
        for(auto i:s)
        {
            if(i==0)
            continue;
            if(j!=i)
            {
                cout<<j-1<<endl;
                return ;
            }
            j++;
        }
        cout<<j-1<<endl;
    }
}
int32_t main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        hello();
    }
}


Comments

Submit
0 Comments
More Questions

1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram