Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define str string
- #define endl '\n'
- #define pb push_back
- #define Mask(i, j) (i & (1 << j))
- #define fi first
- #define se second
- #define all(a) a.begin(), a.end()
- #define foru(c, a, b) for(ite_type c = a; c <= b; ++c)
- #define ford(c, a, b) for(ite_type c = a; c >= b; --c)
- #define db if(debug)
- #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define file(x, sur) if(fopen((x + ".inp").c_str(), "r")) \
- freopen((x + ".inp").c_str(), "r", stdin), \
- freopen((x + sur).c_str(), "w", stdout);
- using namespace std;
- mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
- ll Rand(ll l, ll r) {
- return l + rd() % (r - l + 1);
- }
- bool debug;
- const str name = "not_yet_defined";
- typedef int ite_type;
- typedef pair<int, int> pii;
- typedef complex<double> cnum;
- const int ntest = 200;
- const int maxn = 2e5 + 9, lim = 1e3, max_ai = 1e4;
- const ll inf = 0x3f3f3f3f3f3f3f3f, int_inf = 0x3f3f3f3f;
- const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2},
- dy[] = {1, -1, 2, -2, 2, -2, 1, -1};
- bool maximize(int &a, int b) {
- if(b > a) {a = b; return 1;}
- return 0;
- }
- bool minimize(int &a, int b) {
- if(b < a) {a = b; return 1;}
- return 0;
- }
- int main() {
- faster;
- file(name, ".out");
- debug = 1;
- //file and ios boost
- int n; cin >> n;
- if(n < 4)
- return cout << "IMPOSSIBLE", 0;
- else if(n == 4) {
- cout << "3 4 4 3" << endl << "2 3 4 4" << endl << "1 2 2 3" << endl << "1 1 1 2";
- return 0;
- }
- vector<vector<int>> ans(n + 1, vector<int>(n + 1));
- foru(i, 1, n) ans[i][1] = n;
- foru(i, 1, n)
- foru(j, 2, n)
- ans[i][j] = (j > i ? i : i - 1);
- map<ll, int> pos;
- foru(i, 1, n) {
- ll sum = 0;
- foru(j, 1, n)
- sum += ans[i][j];
- pos[sum] = i;
- }
- foru(j, 1, n) {
- ll sum = 0;
- foru(i, 1, n)
- sum += ans[i][j];
- if(pos[sum]) {
- swap(ans[2][1], ans[2][j]);
- int p = pos[sum];
- swap(ans[p + 1][n], ans[p + 2][n]);
- foru(i, 1, n) {
- foru(j, 1, n)
- cout << ans[i][j] << ' ';
- cout << endl;
- }
- return 0;
- }
- }
- }
- /*
- ♪ ♫ ♪ ♫ ♪
- ♫ ♪ ♫ ♪ ♫
- _ _________________ _ ♩
- |=|[_]|[_]|[_]|[_]|[_]|=|
- | | | | | | | |
- | |___|___|___|___|___| |
- | | | | | | |
- | | | | | | |
- |_._|_._|_._|_._|_._|_._|
- ♩ ♬
- “Spring will be here soon.
- Spring, the season I met you...
- is coming.
- A spring without you...
- ...is coming.”
- */
Advertisement
Add Comment
Please, Sign In to add comment