This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define pb push_back
using namespace std;
vector<int>v;
int n,dp[100009];
int bt(int x,vector<int>cur,int st=0)
{
if(dp[x]!=-1)return dp[x];
if(x==(1<<n)-1){return 0;}
dp[x]=1e9;
for(int i=0;i<n;i++)
{
if((1<<i)&x)continue;
vector<int>con=cur;
int c=0;
for(int j=st*2;j<2*n;j++)
{
if(con[j]*(-1)==v[i])
{
while(j>st*2)
{
c++;
swap(con[j],con[j-1]);
j--;
}
break;
}
}
for(int j=st*2;j<2*n;j++)
{
if(con[j]==v[i])
{
while(j>st*2+1)
{
c++;
swap(con[j],con[j-1]);
j--;
}
break;
}
}
dp[x]=min(dp[x],bt(x+(1<<i),con,st+1)+c);
}
return dp[x];
}
long long count_swaps(vector<int> s) {
n=s.size()/2;
memset(dp,-1,sizeof(dp));
if(n<=8)
{
for(int i=0;i<n*2;i++)
{
if(s[i]<0)continue;
v.push_back(s[i]);
}
return bt(0,s);
}
}
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
62 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |