#include <bits/stdc++.h> using namespace std; long long expe = 0; bool check(int* t, int n){ long long act = 0; for (int i = 0; i < n; ++i){ for (int j = i + 1; j < n; ++j){ if (t[i] > t[j]) act++; } } return act == expe; } int main (){ ios_base::sync_with_stdio(false); cin.tie(0); long long n; long long k; cin >> n >> k; int nasint = n; if (n % 4 > 1){ cout << "NIE" << endl; return 0; } int T[nasint]; long long s = 0; for (int i = 0; i < nasint; ++i){ T[i] = i + 1; } expe = n * (n - 1) / 4; do { if (check(T, nasint)){ s++; if (s == k){ cout << "TAK\n"; for (int i = 0; i < nasint; ++i){ cout << T[i] << " "; } cout << endl; return 0; } } } while(next_permutation(T, T + n)); cout << "NIE" << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; long long expe = 0; bool check(int* t, int n){ long long act = 0; for (int i = 0; i < n; ++i){ for (int j = i + 1; j < n; ++j){ if (t[i] > t[j]) act++; } } return act == expe; } int main (){ ios_base::sync_with_stdio(false); cin.tie(0); long long n; long long k; cin >> n >> k; int nasint = n; if (n % 4 > 1){ cout << "NIE" << endl; return 0; } int T[nasint]; long long s = 0; for (int i = 0; i < nasint; ++i){ T[i] = i + 1; } expe = n * (n - 1) / 4; do { if (check(T, nasint)){ s++; if (s == k){ cout << "TAK\n"; for (int i = 0; i < nasint; ++i){ cout << T[i] << " "; } cout << endl; return 0; } } } while(next_permutation(T, T + n)); cout << "NIE" << endl; } |