Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
761 views

Here is the link for all details of the challenge : https://codingcompetitions.withgoogle.com/codejamio 

in Online Assessments by Expert (110,880 points)
edited by | 761 views

1 Answer

0 like 0 dislike

Problem 1 : Inversions Organize 

Code : 

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    int n;
    cin>>n;
    char mat[2*n+1][2*n+1];
    for(int i=1;i<=2*n;i++)
    {
        string s;
        cin>>s;
        for(int j=1;j<=2*n;j++)
        {
            mat[i][j]=s[j-1];
        }
    }
    int up=0,down=0,right=0,left=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=2*n;j++)
        {
            if(mat[i][j]=='I')
                up++;
        }
    }
    for(int i=n+1;i<=2*n;i++)
    {
        for(int j=1;j<=2*n;j++)
        {
            if(mat[i][j]=='I')
                down++;
        }
    }
    for(int i=1;i<=2*n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(mat[i][j]=='I')
                left++;
        }
    }
    for(int i=1;i<=2*n;i++)
    {
        for(int j=n+1;j<=2*n;j++)
        {
            if(mat[i][j]=='I')
                right++;
        }
    }
    cout<<max(abs(left-right),abs(up-down))<<'\n';
}
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int T=1;
    cin>>T;
    int indx=1;
    while(T--)
    {
        cout<<"Case #"<<indx<<": ";
        solve();
        indx++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
by Expert (110,880 points)