QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695100 | #7778. Turning Permutation | 123456zmy | WA | 1ms | 3932kb | C++17 | 3.3kb | 2024-10-31 19:19:57 | 2024-10-31 19:19:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll __int128
using namespace std;
int n,k;
vector<int>a;
int b[51];
ll cnt0[51],cnt1[51];
ll c[51][51];
ll C(int i,int j)
{
if(i<j||j<0)return 0;
if(i==j||j==0)return 1;
if(c[i][j])return c[i][j];
return c[i][j]=C(i-1,j-1)+C(i-1,j);
}
ll zmy(vector<int> v,int n)
{
// if(v[0]&1)//cnt1
// {
sort(v.begin(),v.end());
int lst=0;
vector<int>a;
for(int x:v)
{
if(x!=lst+1)
{
// if(lst%2==0&&lst!=0)return 0;
// if(x%2==0&&x!=n+1)return 0;
a.push_back(x-lst-1);
}
lst=x;
}
ll ans=cnt1[n-lst];
n-=v.size();
for(auto x:a)ans=min((__int128)2e18,ans*min((__int128)2e18,cnt1[x]*C(n,x))),n-=x;
return ans;
// }
// else//cnt0
// {
// sort(v.begin(),v.end());
// int lst=0;
// vector<int>a;
// for(int x:v)
// {
// if(x!=lst+1)
// {
// // if(lst%2==1&&lst!=0)return 0;
// // if(x%2==1&&x!=n+1)return 0;
// a.push_back(x-lst-1);
// }
// lst=x;
// }
// ll ans=cnt0[n-lst];
// n-=v.size();
// for(auto x:a)ans=min((__int128)2e18,ans*min((__int128)2e18,cnt0[x]*C(n,x))),n-=x;
// return ans;
// }
}
signed main()
{
cnt1[0]=cnt0[0]=1;
cnt1[1]=cnt0[1]=1;
for(int i=2;i<=50;i++)
{
vector<int>v(1);
for(int j=1;j<=i;j++)
{
v[0]=j;
if(j&1)cnt1[i]+=zmy(v,i);
// else cnt0[i]+=zmy(v,i);
// printf("%d ",zmy(v,i));
}//puts("");
cnt1[i]=min((__int128)2e18,cnt1[i]);
cnt0[i]=min((__int128)2e18,cnt0[i]);
}
// for(int i=0;i<=4;i++)printf("%d ",cnt0[i]);puts("");
// for(int i=0;i<=4;i++)printf("%d ",cnt1[i]);
scanf("%lld %lld",&n,&k);
if(k>cnt0[n]+cnt1[n])puts("-1"),exit(0);
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)if (b[j]==0)
{
if(i!=1)
{
if(a[0]&1)
{
if(j&1)
{
if((j>1&&b[j-1]==1)||(j<n&&b[j+1]==1))continue;
}
else
{
if((j>1&&b[j-1]==0)||(j<n&&b[j+1]==0))continue;
}
}
else
{
if(j&1)
{
if((j>1&&b[j-1]==0)||(j<n&&b[j+1]==0))continue;
}
else
{
if((j>1&&b[j-1]==1)||(j<n&&b[j+1]==1))continue;
}
}
}
a.push_back(j);
ll p=zmy(a,n);
// printf("%d\n",zmy(a,n));
// for(auto x:a)printf("%d-",x);puts("");
if (p<k)k-=p;
else
{
b[j]=1;
break;
}
a.pop_back();
}
}
for (int i=0;i<n;i++)printf("%lld ",a[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3896kb
input:
3 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
3 5
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3932kb
input:
4 6
output:
-1
result:
wrong answer 1st numbers differ - expected: '3', found: '-1'