QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354574 | #7778. Turning Permutation | Flamire# | WA | 1ms | 3812kb | C++17 | 1.5kb | 2024-03-15 17:15:25 | 2024-03-15 17:15:26 |
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)
{
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;
if(o==-1)
{
if(i>=2)o=res[i-1]<=res[i]?0:1;else o=-1;
}
else o^=1;
break;
}
else c=nc;
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
input:
3 2
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
3 5
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
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: 3756kb
input:
4 11
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3776kb
input:
3 1
output:
1 2 3
result:
wrong answer 2nd numbers differ - expected: '3', found: '2'