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

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.