Codeforces 1520C. Not Adjacent Matrix Solution

  ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include <bits/stdc++.h>

    using namespace std;

    int main()

    {

        int t,i,j,od,ev;

        cin>>t;

        while(t--)

        {

            long long n;

            od=1;

            ev=2;

            cin>>n;

            if(n==1)

                cout<<1<<endl;

            else if(n==2)

                cout<<"-1"<<endl;

            else

            {

                for(i=1; i<=n; i++)

                {

                    for(j=1; j<=n; j++)

                    {

                        if(od<=n*n)

                        {

                            cout<<od<<" ";

                            od+=2;

                        }

                        else

                        {

                            cout<<ev<<" ";

                            ev+=2;

                        }

                    }

                    cout<<endl;

                }

            }

        }

    }


    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.