#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
vector <int> V;
int main()
{
int n;
long long k;
scanf("%d%lld",&n,&k);
if(n%4==2 or n%4==3)
{
printf("NIE");
return 0;
}
if(n*(n-1)/2<k)
{
printf("NIE");
return 0;
}
for(int i=1;i<=n;i++)
{
V.push_back(i);
}
int licz=0;
while(next_permutation(V.begin(),V.end()))
{
int odp=0;
for(int i=0;i<V.size();i++)
{
for(int j=i+1;j<V.size();j++)
{
if(V[i]>V[j])
{
odp++;
}
}
}
int odp2=0;
for(int i=V.size()-1;i>=0;i--)
{
for(int j=i-1;j>=0;j--)
{
if(V[i]>V[j])
{
odp2++;
}
}
}
if(odp==odp2)
{
licz++;
}
if(licz==k)
{
printf("TAK\n");
for(int i=0;i<V.size();i++)
{
printf("%d ",V[i]);
}
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 64 65 | #include <iostream> #include <vector> #include <math.h> #include <algorithm> using namespace std; vector <int> V; int main() { int n; long long k; scanf("%d%lld",&n,&k); if(n%4==2 or n%4==3) { printf("NIE"); return 0; } if(n*(n-1)/2<k) { printf("NIE"); return 0; } for(int i=1;i<=n;i++) { V.push_back(i); } int licz=0; while(next_permutation(V.begin(),V.end())) { int odp=0; for(int i=0;i<V.size();i++) { for(int j=i+1;j<V.size();j++) { if(V[i]>V[j]) { odp++; } } } int odp2=0; for(int i=V.size()-1;i>=0;i--) { for(int j=i-1;j>=0;j--) { if(V[i]>V[j]) { odp2++; } } } if(odp==odp2) { licz++; } if(licz==k) { printf("TAK\n"); for(int i=0;i<V.size();i++) { printf("%d ",V[i]); } return 0; } } } |
English