Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <algorithm>
- #include <limits>
- #include <string>
- #include <queue>
- #define ll unsigned long long
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<vector<bool>> free(n , vector<bool>(n , true));
- vector<vector<int>> color(n , vector<int>(n , 0));
- queue<pair<int, int>> q;
- for (int i = 0; i < n; i++) {
- q.push(make_pair(i, i));
- q.push(make_pair(n - i - 1, i));
- free[i][i] = false;
- free[n - i - 1][i] = false;
- free[i][i] = 0;
- free[n - i - 1][i] = 0;
- }
- while (!q.empty()) {
- int x = q.front().first, y = q.front().second;
- if (x + 1 < n && free[x + 1][y] ) {
- color[x + 1][y] = color[x][y] % 25 + 1;
- free[x + 1][y] = false;
- q.push(make_pair(x + 1, y));
- }
- if (x - 1 >= 0 && free[x - 1][y]) {
- color[x - 1][y] = color[x][y] % 25 + 1;
- free[x - 1][y] = false;
- q.push(make_pair(x - 1, y));
- }
- if (y + 1 < n && free[x][y + 1]) {
- color[x][y + 1] = color[x][y] % 25 + 1;
- free[x][y + 1] = false;
- q.push(make_pair(x,y + 1));
- }
- if (y - 1 >= 0 && free[x][y - 1]) {
- color[x][y - 1] = color[x][y] % 25 + 1;
- free[x][y - 1] = false;
- q.push(make_pair(x, y - 1));
- }
- q.pop();
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << (char) ('a' + color[i][j]);
- }
- cout << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment