#include"bits/stdtr1c++.h"
using namespace std;
long long a,b,licznik;
short beka[22];
short P[22];
int Licz[22];
bool check()
{
int wynik=0,wynik2=0;
for(int i=1;i<=a;i++)
P[i]=beka[i];
int w=log2(a)+1;
for(int i=0;i<w;i++)
{
for(int j=1;j<=a;j++)
{
if (P[j]%2==1)Licz[P[j]]++;
else wynik+=Licz[P[j]+1];
}
for(int j=1;j<=a;j++)
{
Licz[j]=0;
P[j]/=2;
}
}
for(int i=1;i<=a;i++)
P[i]=beka[a-i+1];
for(int i=0;i<w;i++)
{
for(int j=1;j<=a;j++)
{
if (P[j]%2==1)Licz[P[j]]++;
else wynik2+=Licz[P[j]+1];
}
for(int j=1;j<=a;j++)
{
Licz[j]=0;
P[j]/=2;
}
}
if(wynik==wynik2)return 1;
else return 0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>a>>b;
if(a%4==2||a%3==3)
{
cout<<"NIE";
return 0;
}
for(int i=0; i<=a; i++)
beka[i]=i;
int p=1;
for(int i=1; i<a; i++)
{
p*=(i+1);
}
for(int i=0; i<p; i++)
{
if(check())
{
licznik++;
if(licznik==b)
{
cout<<"TAK\n";
for(int i=1;i<=a;i++)
{
cout<<beka[i]<<' ';
}
return 0;
}
}
next_permutation(beka+1,beka+1+a);
}
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include"bits/stdtr1c++.h" using namespace std; long long a,b,licznik; short beka[22]; short P[22]; int Licz[22]; bool check() { int wynik=0,wynik2=0; for(int i=1;i<=a;i++) P[i]=beka[i]; int w=log2(a)+1; for(int i=0;i<w;i++) { for(int j=1;j<=a;j++) { if (P[j]%2==1)Licz[P[j]]++; else wynik+=Licz[P[j]+1]; } for(int j=1;j<=a;j++) { Licz[j]=0; P[j]/=2; } } for(int i=1;i<=a;i++) P[i]=beka[a-i+1]; for(int i=0;i<w;i++) { for(int j=1;j<=a;j++) { if (P[j]%2==1)Licz[P[j]]++; else wynik2+=Licz[P[j]+1]; } for(int j=1;j<=a;j++) { Licz[j]=0; P[j]/=2; } } if(wynik==wynik2)return 1; else return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin>>a>>b; if(a%4==2||a%3==3) { cout<<"NIE"; return 0; } for(int i=0; i<=a; i++) beka[i]=i; int p=1; for(int i=1; i<a; i++) { p*=(i+1); } for(int i=0; i<p; i++) { if(check()) { licznik++; if(licznik==b) { cout<<"TAK\n"; for(int i=1;i<=a;i++) { cout<<beka[i]<<' '; } return 0; } } next_permutation(beka+1,beka+1+a); } cout<<"NIE"; } |
English