Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- char grid[5][5];
- int pos[3][5];
- string r, c;
- int n;
- bool check() {
- for (int i = 0; i < n; i++) {
- int tmp = 0;
- while (grid[i][tmp] == '.') tmp++;
- if (grid[i][tmp] != r[i]) return 0;
- }
- for (int i = 0; i < n; i++) {
- int tmp = 0;
- while (grid[tmp][i] == '.') tmp++;
- if (grid[tmp][i] != c[i]) return 0;
- }
- return 1;
- }
- bool func(int lv, int now) {
- if (now == 3) {
- if (check()) return 1;
- return 0;
- }
- if (lv == n) {
- return func(0, now + 1);
- }
- for (int i = 0; i < n; i++) {
- if (grid[lv][i] != '.' || pos[now][i]) continue;
- grid[lv][i] = 'A' + now;
- pos[now][i] = 1;
- if (func(lv + 1, now)) return 1;
- grid[lv][i] = '.';
- pos[now][i] = 0;
- }
- return 0;
- }
- int main() {
- cin >> n >> r >> c;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- grid[i][j] = '.';
- if (func(0, 0)) {
- cout << "Yes\n";
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << grid[i][j];
- }
- cout << '\n';
- }
- }
- else cout << "No\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment