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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 `#include #include #include #include #include #include #include #include #define ll long long using namespace std; vector > D; ll oo = (ll)1e18 + 1; ll getVal(ll n, ll inv) { if(inv ==0)return 1; if(n<=1)return 0; ll all = n*(n-1)/2; if(inv>all)return 0; if(inv > all - inv)inv = all -inv; if(inv >= D[n].size())return oo; return D[n][inv]; } void fill_D(int n){ D.push_back(vector()); D.push_back(vector()); for(ll nn=2;nn R; R.push_back(1); for(ll inv =1;inv<=nn*(nn-1)/2;inv++){ ll r =0; for(ll s = max(1LL,nn-inv);s<=nn;s++){ ll p = nn-s; r += getVal(nn-1,(inv-p)); if(r>=oo){ r=oo; break; } } if(r==oo)break; else R.push_back(r); } D.push_back(R); // if(nn%1000==0)cout <> n >>k; //n = 5;k=1; fill_D(n+1); if (n*(n-1)%4 !=0 ){ cout <<"NIE\n"; return 0; } ll all = getVal(n, n*(n-1)/4); if(k>all) { cout <<"NIE\n"; return 0; } set S; for(int i=1;i<=n;i++)S.insert(i); cout <<"TAK\n"; ll need_inv = n*(n-1)/4; for(int i=0;i=k) { cout << *it << " "; S.erase(it); k -=skipped; need_inv -=el; break; } else { skipped +=av; } it++; } } cout <