QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344061#7778. Turning Permutationhl666WA 0ms4024kbC++171.9kb2024-03-03 14:54:462024-03-03 14:54:47

Judging History

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

  • [2024-03-03 14:54:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4024kb
  • [2024-03-03 14:54:46]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
const int N=55;
int n,k,a[N],cs[N],pos[N],f[N][N][2]; // 0: i-1 on i's left; 1: i-1 on i's right
inline int calc(void)
{
    RI i,j,k,tp; memset(f,0,sizeof(f)); int len=0;
    if (cs[1]&&cs[2])
    {
    	if (pos[1]<pos[2]) f[2][0][0]=1; else f[2][0][1]=1;
    } else if (cs[1]&&!cs[2]) len=1,f[2][1][0]=1;
    else if (!cs[1]&&cs[2]) len=1,f[2][0][1]=1;
    else len=2,f[2][1][1]=f[2][2][0]=1;
    for (i=2;i<n;++i)
    {
		if (cs[i+1])
    	{
    		if (cs[i])
    		{
    			if (pos[i+1]<pos[i]) f[i+1][0][1]=f[i][0][0];
				else f[i+1][0][0]=f[i][0][1];
    		} else
			{
				for (j=1;j<=len;++j) f[i+1][0][1]+=f[i][j][0];
			}
    		continue;
    	}
    	for (j=0;j<=len;++j)
    	{
	        for (tp=0;tp<2;++tp) if (f[i][j][tp])
	        {
	        	if (tp==0)
	        	{
	        		for (k=1;k<=j;++k) f[i+1][k][1]+=f[i][j][tp];
	        	} else
	        	{
	        		for (k=j+1;k<=len+1;++k) f[i+1][k][0]+=f[i][j][tp];
	        	}
	        }
	    }
	    ++len;
    }
    int ret=0; for (i=1;i<=len;++i) ret+=f[n][i][0]+f[n][i][1]; return ret;
}
signed main()
{
    RI p,v,i; for (scanf("%lld%lld",&n,&k),p=1;p<n;++p)
    {
        int filled=-1;
        for (v=1;v<=n;++v) if (!cs[v])
        {
            cs[v]=1; a[p]=v; pos[v]=p;
            for (i=1;i<=n;++i) if (!cs[i]) pos[i]=p+1;
            bool flag=1; for (i=2;i<=n;++i)
            if ((pos[i]-pos[i-1])*(pos[i]-pos[i+1])<0) { flag=0; break; }
            if (!flag) continue; int tmp=calc();
            if (tmp>=k) { filled=v; break; } else k-=tmp,cs[v]=0;
        }
        if (filled==-1) return puts("-1"),0; else a[p]=filled;        
    }
    for (i=1;i<=n;++i) if (!cs[i]) a[n]=i;
    for (i=1;i<=n;++i) printf("%lld ",a[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2

output:

2 1 3 

result:

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

Test #2:

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

input:

3 5

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

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: 3712kb

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

result:

wrong answer 1st numbers differ - expected: '1', found: '-1'