Guest User

Untitled

a guest
Aug 17th, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define str string
  4. #define endl '\n'
  5. #define pb push_back
  6. #define Mask(i, j) (i & (1 << j))
  7. #define fi first
  8. #define se second
  9. #define all(a) a.begin(), a.end()
  10. #define foru(c, a, b) for(ite_type c = a; c <= b; ++c)
  11. #define ford(c, a, b) for(ite_type c = a; c >= b; --c)
  12. #define db if(debug)
  13. #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  14. #define file(x, sur) if(fopen((x + ".inp").c_str(), "r")) \
  15. freopen((x + ".inp").c_str(), "r", stdin), \
  16. freopen((x + sur).c_str(), "w", stdout);
  17.  
  18. using namespace std;
  19.  
  20. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  21.  
  22. ll Rand(ll l, ll r) {
  23. return l + rd() % (r - l + 1);
  24. }
  25.  
  26. bool debug;
  27. const str name = "not_yet_defined";
  28. typedef int ite_type;
  29. typedef pair<int, int> pii;
  30. typedef complex<double> cnum;
  31.  
  32. const int ntest = 200;
  33. const int maxn = 2e5 + 9, lim = 1e3, max_ai = 1e4;
  34. const ll inf = 0x3f3f3f3f3f3f3f3f, int_inf = 0x3f3f3f3f;
  35. const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2},
  36. dy[] = {1, -1, 2, -2, 2, -2, 1, -1};
  37.  
  38. bool maximize(int &a, int b) {
  39. if(b > a) {a = b; return 1;}
  40. return 0;
  41. }
  42.  
  43. bool minimize(int &a, int b) {
  44. if(b < a) {a = b; return 1;}
  45. return 0;
  46. }
  47.  
  48. int main() {
  49. faster;
  50. file(name, ".out");
  51. debug = 1;
  52.  
  53. //file and ios boost
  54.  
  55. int n; cin >> n;
  56. if(n < 4)
  57. return cout << "IMPOSSIBLE", 0;
  58. else if(n == 4) {
  59. cout << "3 4 4 3" << endl << "2 3 4 4" << endl << "1 2 2 3" << endl << "1 1 1 2";
  60. return 0;
  61. }
  62.  
  63. vector<vector<int>> ans(n + 1, vector<int>(n + 1));
  64. foru(i, 1, n) ans[i][1] = n;
  65. foru(i, 1, n)
  66. foru(j, 2, n)
  67. ans[i][j] = (j > i ? i : i - 1);
  68.  
  69. map<ll, int> pos;
  70. foru(i, 1, n) {
  71. ll sum = 0;
  72. foru(j, 1, n)
  73. sum += ans[i][j];
  74. pos[sum] = i;
  75. }
  76.  
  77. foru(j, 1, n) {
  78. ll sum = 0;
  79. foru(i, 1, n)
  80. sum += ans[i][j];
  81. if(pos[sum]) {
  82. swap(ans[2][1], ans[2][j]);
  83. int p = pos[sum];
  84. swap(ans[p + 1][n], ans[p + 2][n]);
  85. foru(i, 1, n) {
  86. foru(j, 1, n)
  87. cout << ans[i][j] << ' ';
  88. cout << endl;
  89. }
  90. return 0;
  91. }
  92. }
  93. }
  94.  
  95. /*
  96. ♪ ♫ ♪ ♫ ♪
  97. ♫ ♪ ♫ ♪ ♫
  98. _ _________________ _ ♩
  99.  
  100. |=|[_]|[_]|[_]|[_]|[_]|=|
  101. | | | | | | | |
  102. | |___|___|___|___|___| |
  103. | | | | | | |
  104. | | | | | | |
  105. |_._|_._|_._|_._|_._|_._|
  106. ♩ ♬
  107.  
  108. “Spring will be here soon.
  109. Spring, the season I met you...
  110. is coming.
  111. A spring without you...
  112. ...is coming.”
  113. */
  114.  
Advertisement
Add Comment
Please, Sign In to add comment