#include<bits/stdc++.h>
using namespace std;
int tab[1000000];
int tab2[15]={0,1,0,0,6,22,0,0,3836,29228,0,0};
int silnia(int a)
{
int pom=1;
for(int x=1;x<=a;x++)
pom*=x;
return pom;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int x,b;
cin>>x>>b;
if(x%4==2||x%4==3)
cout<<"NIE";
else
{
if(x>11)
cout<<"TAK"<<'\n';
else
{
if(b>tab2[x])
{
cout<<"NIE";
return 0;
}
else
cout<<"TAK"<<'\n';
}
for(int y=0;y<x;y++)
tab[y]=y+1;
int pom=0,licz=0;
while(pom!=silnia(x))
{
int pom1=0,pom2=0;
for(int y=0;y<x;y++)
for(int z=y+1;z<x;z++)
{
if(tab[z]>tab[y])
pom1++;
else
pom2++;
}
if(pom1==pom2)
{
licz++;
if(licz==b)
for(int y=0;y<x;y++)
cout<<tab[y]<<" ";
}
pom++;
next_permutation(tab,tab+x);
}
}
return 0;
}
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 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include<bits/stdc++.h> using namespace std; int tab[1000000]; int tab2[15]={0,1,0,0,6,22,0,0,3836,29228,0,0}; int silnia(int a) { int pom=1; for(int x=1;x<=a;x++) pom*=x; return pom; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int x,b; cin>>x>>b; if(x%4==2||x%4==3) cout<<"NIE"; else { if(x>11) cout<<"TAK"<<'\n'; else { if(b>tab2[x]) { cout<<"NIE"; return 0; } else cout<<"TAK"<<'\n'; } for(int y=0;y<x;y++) tab[y]=y+1; int pom=0,licz=0; while(pom!=silnia(x)) { int pom1=0,pom2=0; for(int y=0;y<x;y++) for(int z=y+1;z<x;z++) { if(tab[z]>tab[y]) pom1++; else pom2++; } if(pom1==pom2) { licz++; if(licz==b) for(int y=0;y<x;y++) cout<<tab[y]<<" "; } pom++; next_permutation(tab,tab+x); } } return 0; } |
English