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

1721A - Image
1180C - Valeriy and Deque
557A - Ilya and Diplomas
1037D - Valid BFS
1144F - Graph Without Long Directed Paths
1228A - Distinct Digits
355B - Vasya and Public Transport
1230A - Dawid and Bags of Candies
1530A - Binary Decimal
1472D - Even-Odd Game
441C - Valera and Tubes
1328E - Tree Queries
265A - Colorful Stones (Simplified Edition)
296A - Yaroslav and Permutations
967B - Watering System
152A - Marks
1398A - Bad Triangle
137A - Postcards and photos
1674D - A-B-C Sort
334A - Candy Bags
855A - Tom Riddle's Diary
1417A - Copy-paste
1038A - Equality
1061A - Coins
1676E - Eating Queries
1447A - Add Candies
1721D - Maximum AND
363C - Fixing Typos
1401A - Distance and Axis
658A - Bear and Reverse Radewoosh