323A - Black-and-White Cube - CodeForces Solution


combinatorics constructive algorithms *1600

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <set>
#include <numeric>
#include <array>
#include <algorithm>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lb lower_bound
#define ub upper_bound
#define setbits(x) __builtin_popcountll(x)
#include <stack>
#define unsigned int 
using namespace std;
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <functional>
using namespace std;

#define PI 3.14159265358979323846264
#define ii pair<int,int>
#define iii pair<int, pair<int, int>>





using namespace std;
#define int long long
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b, a%b);
}

void normalize(vector<int> &v)
{
    set<int> s;
    for(auto i : v)
        s.insert(i);
    map<int, int> m;
    int cnt = 1;
    for(auto i : s)
        m[i] = cnt++;
    for(auto &i : v)
        i = m[i];
    
}


int get(int n)
{
    if(n == 1)
        return 1;
    return n + get(n/2);
}
const int n = 2e5 + 1;
int MOD = 1e9 + 7;
//  int MOD =  998244353;
int fact[1000000];
map<string, int> mp;

/// @brief 
/// @param n 
/// @return 
int sum(int n)
{
    return n * (n+1 ) /2 ;
}
long long modular_inverse(long long a, long long m) {
    // Extended Euclidean Algorithm
    long long m0 = m;
    long long x0 = 0, x1 = 1;

    while (a > 1) {
        long long q = a / m;
        long long t = m;

        m = a % m, a = t;
        t = x0;

        x0 = x1 - q * x0;
        x1 = t;
    }

    if (x1 < 0) {
        x1 += m0;
    }

    return x1;
}
long long modInverse(long long a) {
    long long p = MOD;
    long long result = 1;
    long long exponent = p - 2;

    while (exponent > 0) {
        if (exponent % 2 == 1) {
            result = (result * a) % p;
        }
        a = (a * a) % p;
        exponent /= 2;
    }

    return result;
}

int comb(int n, int k) {
    if(k > n)
        return 0;
    if(k < 0)
        return 0;
    if(k>n-k)
        k = n-k;
    int ret = 1;
    for(int i = 0;i<k;i++)
    {
        ret *= n-i;
        ret /= i+1;
    }

    return ret;

}



int combMod(int n, int k) {
    if(n < k) return 0;
    return fact[n] * modInverse(fact[k]) %MOD * modInverse(fact[n-k]) % MOD;
}

int permute(int n, int k) {
    if(k > n)
        return 0;
    int ret = 1;
    ret = fact[n] * modInverse(fact[n - k]) % MOD;
    return ret;
}
int power(int a, int b)
{
    if(b == 0)
        return 1;
    int ret = power(a, b/2);
    ret *= ret;
    ret %= MOD;
    if(b&1)
        ret *= a;
    ret %= MOD;
    return ret;
}
bool check(vector<int> &v, int k)
{
    int n = v.size();
    int cnt = 0;
    vector<int> b;
    for(int i = n-k;i<n;i++)
        b.push_back(v[i]);
    for(int i = 0;i<n-k;i++)
        b.push_back(v[i]);
    for(int i = 0;i<n;i++)
        cnt += b[i] > v[i];
    return cnt >= k;

}


int sum1toN(int n)
{
    return n * (n+1) / 2;
}

int sum1toN(int l, int r)
{
    return sum1toN(r) - sum1toN(l-1);
}

int sumDigits(int n)
{
    int ret = 0;
    while(n)
    {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int get(char c) {
    if('0' <= c && c <= '9')
        return c - '0';
    if('A' <= c && c <= 'Z')
        return c - 'A' + 10;
    if('a' <= c && c <= 'z')
        return c - 'a' + 36;
    if(c == '-')
        return 62;
    return 63;
}
vector<vector<int>> result;
vector<int> currentSet;
vector<int> currentPut;


void powerSet(int i = 0) {
    if(i == currentSet.size()) {

        result.push_back(currentPut);
        return;
    }

    currentPut.push_back(currentSet[i]);
    powerSet(i+1);

    currentPut.pop_back();
    powerSet(i+1);
    


}
void solve() {
   
    int n;
    cin>>n;
    if(n % 2 == 1) {
        cout<<-1<<endl;
        return;
    }
    map<int, char>eval;
    eval[0] = 'w';
    eval[1] = 'b';

    for(int layer = 0; layer < n; layer++) {
        int c = layer % 2;

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                int level = min({i, j, n - i - 1, n - j - 1});
                int cur = level %2;
                if(c) cur = !cur;
                cout<<eval[cur];
            }
            cout << endl;
        }
        cout << endl;



    }

    
                

}
            



main() {
    IOS;
    fact[0] = 1;
    
    for(int i=1;i<=n;i++)
        fact[i] = i*fact[i-1]%MOD;
    int t = 1;
    //cin >> t;
    //while(t--)
        solve();
    

    return 0;
    
}

// Path: eatingCandies.cpp


Comments

Submit
0 Comments
More Questions

232. Implement Queue using Stacks
844. Backspace String Compare
20. Valid Parentheses
746. Min Cost Climbing Stairs
392. Is Subsequence
70. Climbing Stairs
53. Maximum Subarray
1527A. And Then There Were K
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
318. Maximum Product of Word Lengths
448. Find All Numbers Disappeared in an Array
1155. Number of Dice Rolls With Target Sum
415. Add Strings
22. Generate Parentheses
13. Roman to Integer
2. Add Two Numbers
515. Find Largest Value in Each Tree Row
345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name