QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694903#7778. Turning Permutation123456zmy#WA 0ms3932kbC++172.2kb2024-10-31 18:54:432024-10-31 18:54:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 18:54:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3932kb
  • [2024-10-31 18:54:43]
  • 提交

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*=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*=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("");
    }
    // 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)
        {
            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]);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3848kb

input:

3 2

output:

2 1 3 

result:

ok 3 number(s): "2 1 3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

3 5

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

4 6

output:

3 1 2 4 

result:

ok 4 number(s): "3 1 2 4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3932kb

input:

4 11

output:

-1

result:

ok 1 number(s): "-1"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3836kb

input:

3 1

output:

1 2 3 

result:

wrong answer 2nd numbers differ - expected: '3', found: '2'