Techgig Code-Gladiators 2020 (winner -Himanshu Singh)

but the sad part is that , this you don’t apply in your life .

Bro, I don’t know who you are. I had not given anyone any hints, nor going to give. It was just a normal conversation and thats it. So just end this and don’t ruin discuss by your shitty conversations

well nobody has got that much time to judge you based on ur rating and stuff , but you yourself do and no one is responsible for that.

No issues … bro …U win and I lose , let’s do some work which is more important …Ok…

1 Like

How many finalists are expected this year.

last year they select top 500 , This year i think same , but not sure .

1 Like

Did anyone here solve question 2 all 10 cases ? Can you please share logic ?

@nishant403 how u did 2nd one please can u share your code as contest ended.

Now the contest is over.
So Please send the solution of both the problems, anyone who solved them.

Problem 2 was really Interesting. Where can I practice more such problems ?
And also can someone share it’s solution ?

1 Like

@ssrivastava990 @hetp111 Please share the solution or approaach for 1st problem.

It was a standard dp problem, I can’t access my code though.

It was a dp-problem with a small mathematical formula.
Here’s my code:

#include<bits/stdc++.h>

using namespace std;

using ll = long long;

ll mod = 1e9+7;

ll n,_ro,_rg,_or,_og,_gr,_go;

ll fac[100010];

ll rpow(ll a,ll b)

{

    if(b==0)

    return 1;

    if(b==1)

    return a;

    ll ret1=rpow(a,b/2)%mod;

    ll ret2=(ret1*ret1)%mod;

    if(b%2==0)

    return ret2%mod;

    return (ret2*a)%mod;

}

ll inv(ll n)

{

    return rpow(n,mod-2);

}

ll ncr(ll n,ll r)

{

    if(n<r)

    return 0;

    // cout<<n<<" "<<r<<endl;

    return (fac[n]*((inv(fac[r])*inv(fac[n-r]))%mod))%mod;

}

ll goo(ll ss) {

    // cout<<ss<<endl;

    ll ret = ncr(n-1,ss-1);

    return ret;

}

ll dp[4][11][11][11][11][11][11];

ll fil(ll pc , ll ss) {

    

    if(dp[pc][_rg][_ro][_go][_gr][_og][_or]!=-1)

    return dp[pc][_rg][_ro][_go][_gr][_og][_or];

    if(ss>n) {
    indent preformatted text by 4 spaces
        return 0;

    }

    ll ret = goo(ss)%mod;

    if(pc == 1) {

        if(_ro > 0) {

            _ro--;

            ret = ((ret%mod) + (fil(2,ss+1)%mod))%mod;

            _ro++;

        }

        if(_rg>0) {

            _rg--;

            ret = ((ret%mod) + (fil(3,ss+1)%mod))%mod;

            _rg++;

        }

    }

    else if(pc == 2) {

        if(_og > 0) {

            _og--;

            ret = ((ret%mod) + (fil(3,ss+1)%mod))%mod;

            _og++;

        }

        if(_or>0) {

            _or--;

            ret = ((ret%mod) + (fil(1,ss+1)%mod))%mod;

            _or++;

        }

    }

    else {

        if(_gr > 0) {

            _gr--;

            ret = ((ret%mod) + (fil(1,ss+1)%mod))%mod;

            _gr++;

        }

        if(_go>0) {

            _go--;

            ret = ((ret%mod) + (fil(2,ss+1)%mod))%mod;

            _go++;

        }

    }

    return dp[pc][_rg][_ro][_go][_gr][_og][_or]=ret%mod;

}

ll foo(ll ai) {

    // cout<<fil(1,1)<<" "<<fil(2,1)<<" "<<fil(3,1)<<endl;

    ll ans= (fil(1,1)%mod) + (fil(2,1)%mod) + (fil(3,1)%mod) ;

    ans%=mod;

    return ans;

}

int main() {

    memset(dp,-1,sizeof(dp));

    fac[0]=1;

    for(ll i=1;i<=100000;i++) {

        fac[i] = ( (fac[i-1] %mod) * (i%mod) )%mod;

    }

    cin>>n;

    cin>>_ro>>_rg>>_or>>_og>>_gr>>_go;

    ll res = foo(0);

    cout<<res<<endl;

}

I don’t know if it’s ok to share my solution if it’s not allowed someone please let me know.

1 Like

I was able to solve 1st question using DP.
But I think that my approach is not good as I used 12-D array to find solution using DP.
1 dimension for previous doctor, 1 for patient and 10 dimensions for 10 doctors availability -> Total 12 D array.
It is a very lengthy approach.
Please anyone share a short approach or other DP solution.
If possible, Please share code also or share the approach.

Take an Integer mask instead of 10 integers, If ith bit is set then doctor is taken, else not taken.
I think you know the rest. (Search about bitmask dp if you want more detail.)

1 Like

@hetp111 @ssrivastava990 Can You Share Your Approach and code For First Problem of Code Gladiators , I Kept thinking of Bitmasking and i am sure it will be a 2^n Solution.
But the Problem is i was not able to implement it.

hey , how did you become the moderator & what benefits do you get with this role ??

1 Like

I dont know… Maybe I was worthy.

wdym ?

You can read this if interested Discourse Moderation Guide - moderators - Discourse Meta

Thanks @hetp111 for the help.

1 Like