#include <bits/stdc++.h> using namespace std; typedef long long ll; ll tab[251000]; ll Check(ll tab[], ll n){ ll counting = 0; for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(tab[j] < tab[i]) counting++; return counting; } int main(){ ios_base::sync_with_stdio(0); ll n, k; cin >> n >> k; for(int i = 0; i < n; i++) tab[i] = i+1; do{ ll pom1 = Check(tab, n); reverse(tab, tab+n); ll pom2 = Check(tab, n); reverse(tab, tab+n); if(pom1 == pom2){ k--; if(k == 0){ cout << "TAK\n"; for(int i = 0; i < n; i++) cout << tab[i] << " "; return 0; } } }while(next_permutation(tab, tab+n)); cout << "NIE"; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll tab[251000]; ll Check(ll tab[], ll n){ ll counting = 0; for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(tab[j] < tab[i]) counting++; return counting; } int main(){ ios_base::sync_with_stdio(0); ll n, k; cin >> n >> k; for(int i = 0; i < n; i++) tab[i] = i+1; do{ ll pom1 = Check(tab, n); reverse(tab, tab+n); ll pom2 = Check(tab, n); reverse(tab, tab+n); if(pom1 == pom2){ k--; if(k == 0){ cout << "TAK\n"; for(int i = 0; i < n; i++) cout << tab[i] << " "; return 0; } } }while(next_permutation(tab, tab+n)); cout << "NIE"; } |