1221B - Knights - CodeForces Solution


constructive algorithms greedy *1100

Please click on ads to support us..

Python Code:

n = int(input())
a = 1
for c in range (0,n):
    for v in range (0,n):
        if a == 1:
            print("W" if v % 2 == 0 else "B", end="")
        else:
            print("B" if v % 2 == 0 else "W",end="")
    a = 1 if a == 0 else 0
    print()

C++ Code:

    #include <bits/stdc++.h>
    using namespace std;

    #define oset                 tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define M                    1e10+9
    #define pi                     3.14159265358979323846
    #define cel(x,a)            (((x) + (a) - 1) / (a))
    #define int                   long long
    #define pii                     pair<int,int>
    #define pb                     push_back
    #define lb                      lower_bound
    #define ub                     upper_bound
    #define ps(x,y)              fixed<<setprecision(y)<<x
    #define pf(x,y)              setfill('x')<<setw(y)
    #define mem(a,b)             memset(a,b,sizeof(a))
    #define F                        first
    #define S                        second
    #define countofbits(n)   __builtin_popcount(n)
    #define lcm(m, n)         (((m) / __gcd((m), (n)))*(n))
    #define all(v)                  v.begin(), v.end()
    #define sz(s)                   (int)(s.size())
    #define getline(s)           getline(cin >> ws, s)
    #define YES                   cout<<"YES"<<endl
    #define NO                    cout<<"NO"<<endl
    #define cz                     cout<<0<<endl
    #define Kremes              int t; cin>>t; while(t--)
    #define q                         queue<int>
    #define vi                       vector<int>
    #define vp                      vector<pair<int,int>>
    #define vs                      vector<string>
    #define fre(i,a,b)            for(int (i)=(a);(i)<(b);i++)
    #define fri(i,a,b)             for(int (i)=(a);(i)<=(b);i++)
    #define inp(a,n)             for(int i=0; i<n; i++) cin>>a[i];
    #define ct(a)                   cout<<a<<"\n"
    #define cts(a)                   cout<<(a)<<" "
    #define cn                 cout<<-1<<endl
    #define ndl                cout<<"\n"
    #define nl                 cout<<endl
    #define vi                  vector<int>
    #define mp                  map<int,int>
    #define lst                   (cl.size()-1)
    #define tell_time            cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << "\n";
    #define r(s)                     reverse((s).begin(),(s).end())

    void cline()          { cout << '\n';}
    template <typename T, typename... V>
    void cline(T t, V... v) {cout << t; if (sizeof...(v))cout << ' '; cline(v...);}
    void cspc()          { cout << ' ';}
    template <typename T, typename... V>
    void cspc(T t, V... v) {cout << t; if (sizeof...(v))cout << ' '; cspc(v...);}

    const int N = 1000007;

    void Poffertjes(){
     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        // freopen("##.in", "r", stdin);
        //#ifndef ONLINE_JUDGE
         //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
       // #endif
    }

    int min (int x, int y) {
        return (x < y) ? x : y;
    }

     //your code goes from here............................................................
    void makememove(){
        int n; cin>>n;
        fre(i,0,n){
          fre(j,0,n){
           cout<< (((i+j)%2==0)?"W":"B");
          }
          nl;
        }
      }

    int32_t main(){
            Poffertjes();
         //Kremes
         {
              makememove();
              tell_time;
        }
          return 0;

    }
   


Comments

Submit
0 Comments
More Questions

72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)