Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define x first
- #define y second
- using namespace std;
- typedef long long ll;
- const int N = 1e3 + 10;
- int n, a[N][N], b[N], c[N];
- int x= 0, y = 1;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin >> n;
- for (int i = 1; i <= n * n; ++i)
- {
- cin >> c[i];
- ++b[c[i]];
- }
- bool fl = 0;
- for (int i = 1; i <= N; ++i)
- {
- int e = b[i];
- if (b[i] == 0) continue;
- for (int j = 1; j <= e / 4; ++j)
- {
- ++x;
- if (x > n / 2) x = 1, ++y;
- if (y > n / 2) break;
- a[y][x] = i;
- b[i] -= 4;
- }
- if (b[i] != 0) fl = 1;
- }
- if (n % 2 == 0 && fl) {
- cout << "no";
- return 0;
- }
- int cnt = 0;
- if (n % 2 != 0)
- {
- fl = 0;
- int x = 0, y = n / 2 + 1;
- for (int i = 1; i <= N; ++i)
- {
- int e = b[i];
- if (b[i] != 0)
- {
- for (int j = 1; j <= e / 2; ++j)
- {
- ++x;
- if (x > n / 2)
- {
- fl = 1, y = 0, x = n / 2 + 1;
- break;
- }
- a[y][x] = i, a[y][n - x + 1] = i;
- b[i] -= 2;
- }
- e = b[i];
- if (fl)
- {
- for (int j = 1; j <= e / 2; ++j)
- {
- ++y;
- if (y > n / 2)
- {
- cout << "no";
- return 0;
- }
- a[y][x] = i, a[n -y + 1][x] = i;
- b[i] -= 2;
- }
- }
- if (b[i] != 0) ++cnt, a[n / 2 + 1][n / 2 + 1] = i;
- }
- if (cnt > 1)
- {
- cout << "no";
- return 0;
- }
- }
- }
- for (int i = 1; i <= n / 2; ++i)
- {
- for (int j = 1; j <= n / 2; ++j)
- {
- a[n - i + 1][j] = a[i][j];
- a[n - i + 1][n - j + 1] = a[i][j];
- a[i][n - j + 1] = a[i][j];
- }
- }
- cout << "yes" << endl;
- for (int i = 1; i <= n; ++i)
- {
- for (int j = 1; j <= n ;++j)
- {
- cout << a[i][j] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement