Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4. using namespace std;
  5. typedef long long ll;
  6. const int N = 1e3 + 10;
  7.  
  8. int n, a[N][N], b[N], c[N];
  9.  
  10. int x= 0, y = 1;
  11.  
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);
  16. cin >> n;
  17.  
  18. for (int i = 1; i <= n * n; ++i)
  19. {
  20. cin >> c[i];
  21. ++b[c[i]];
  22. }
  23. bool fl = 0;
  24. for (int i = 1; i <= N; ++i)
  25. {
  26. int e = b[i];
  27. if (b[i] == 0) continue;
  28. for (int j = 1; j <= e / 4; ++j)
  29. {
  30. ++x;
  31. if (x > n / 2) x = 1, ++y;
  32. if (y > n / 2) break;
  33. a[y][x] = i;
  34. b[i] -= 4;
  35. }
  36. if (b[i] != 0) fl = 1;
  37. }
  38. if (n % 2 == 0 && fl) {
  39. cout << "no";
  40. return 0;
  41. }
  42. int cnt = 0;
  43. if (n % 2 != 0)
  44. {
  45. fl = 0;
  46. int x = 0, y = n / 2 + 1;
  47. for (int i = 1; i <= N; ++i)
  48. {
  49. int e = b[i];
  50. if (b[i] != 0)
  51. {
  52. for (int j = 1; j <= e / 2; ++j)
  53. {
  54. ++x;
  55. if (x > n / 2)
  56. {
  57. fl = 1, y = 0, x = n / 2 + 1;
  58. break;
  59. }
  60. a[y][x] = i, a[y][n - x + 1] = i;
  61. b[i] -= 2;
  62. }
  63. e = b[i];
  64. if (fl)
  65. {
  66. for (int j = 1; j <= e / 2; ++j)
  67. {
  68. ++y;
  69. if (y > n / 2)
  70. {
  71. cout << "no";
  72. return 0;
  73. }
  74. a[y][x] = i, a[n -y + 1][x] = i;
  75. b[i] -= 2;
  76. }
  77.  
  78. }
  79. if (b[i] != 0) ++cnt, a[n / 2 + 1][n / 2 + 1] = i;
  80. }
  81. if (cnt > 1)
  82. {
  83. cout << "no";
  84. return 0;
  85. }
  86. }
  87. }
  88. for (int i = 1; i <= n / 2; ++i)
  89. {
  90. for (int j = 1; j <= n / 2; ++j)
  91. {
  92. a[n - i + 1][j] = a[i][j];
  93. a[n - i + 1][n - j + 1] = a[i][j];
  94. a[i][n - j + 1] = a[i][j];
  95. }
  96. }
  97. cout << "yes" << endl;
  98. for (int i = 1; i <= n; ++i)
  99. {
  100. for (int j = 1; j <= n ;++j)
  101. {
  102. cout << a[i][j] << ' ';
  103. }
  104. cout << endl;
  105. }
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement