Solution to the problem 'A' from 'Hello 2022' Contest (Codeforces)

Here's my solution to problem  A from the contest 'Hello 2022' of Codeforces. 

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n,k,m=0;
        cin>>n>>k;
        if(n%2==0){
            if(k<=n/2){
                for(int i=1;i<=n;i++){
                    for(int j=1;j<=n;j++){
                        if(k>0 && i==2*m+1&&j==2*m+1){
                            cout<<'R';
                            k--;
                            m++;
                        }
                        else cout<<'.';
                    }
                    cout<<'\n';
                }
            }
            else cout<<-1<<'\n';
        }
        else{
            if(k<=(n/2)+1){
                for(int i=1;i<=n;i++){
                    for(int j=1;j<=n;j++){
                        if(k>0 && i==2*m+1&&j==2*m+1){
                            cout<<'R';
                            k--;
                            m++;
                        }
                        else cout<<'.';
                    }
                    cout<<'\n';
                }
            }
            else cout<<-1<<'\n';
        }
    }
    return 0;
}

Comments

Popular posts from this blog

Solution of 'Tom Riddle's Diary' (Codeforces)

Solution to the problem 'Red Light, Green Light' from Codechef

Solution to the problem 'The Squid Game' form Codechef