QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354576 | #7778. Turning Permutation | Flamire# | WA | 1ms | 3796kb | C++17 | 1.5kb | 2024-03-15 17:19:53 | 2024-03-15 17:19:54 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,res[111];ll k,dp[111][111][2];
int main()
{
scanf("%d%lld",&n,&k);
dp[1][1][0]=dp[1][1][1]=1;//0: next dec 1:next inc
for(int i=1;i<n;++i)
{
for(int j=1;j<=i;++j)
{
for(int k=1;k<=i+1;++k)
{
if(k<=j)
{
dp[i+1][k][1]=min((ll)2e18,dp[i][j][0]+dp[i+1][k][1]);
}
else
{
dp[i+1][k][0]=min((ll)2e18,dp[i][j][1]+dp[i+1][k][0]);
}
}
}
}
ll ans=0;
for(int i=1;i<=n;++i)ans=min((ll)2e18,ans+dp[n][i][0]+dp[n][i][1]);
// for(int i=1;i<=n;++i)
// {
// for(int j=1;j<=i;++j)printf("{%lld,%lld} ",dp[i][j][0],dp[i][j][1]);putchar(10);
// }
if(ans<k)printf("-1\n");
else
{
int o=-1;
for(int i=1;i<=n;++i)
{
ll c=0;
for(int j=1;j<=n-i+1;++j)
{
if(i==1)o=-1;else o=!(res[i-1]<=j);
ll cur=min((ll)2e18,o==-1?(n-i+1!=1?dp[n-i+1][j][0]+dp[n-i+1][j][1]:1):dp[n-i+1][j][o]);
ll nc=min((ll)2e18,c+cur);
// printf("i:%d j:%d o:%d nc:%lld cur:%lld k:%lld\n",i,j,o,nc,cur,k);
if(nc>=k)
{
res[i]=j;
k-=c;
break;
}
else c=nc;
}
}
// for(int i=1;i<=n;++i)printf("%d ",res[i]);putchar(10);
vector<int> tt;for(int i=1;i<=n;++i)tt.push_back(i);
for(int i=1;i<=n;++i)
{
int x=res[i];
res[i]=tt[x-1];
tt.erase(tt.begin()+x-1);
}
for(int i=1;i<=n;++i)printf("%d ",res[i]);putchar(10);
// putchar(10);/
}
fclose(stdin);fclose(stdout);return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
3 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
3 5
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
4 6
output:
3 1 4 2
result:
wrong answer 3rd numbers differ - expected: '2', found: '4'