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 "bits/stdc++.h"
#include "shoes.h"
using namespace std;
#define ll long long
bool check(vector<int> &s, int len)
{
for(int j = 0; j<len-1; j+=2)
{
if(s[j]+s[j+1]!=0)
return false;
else if(s[j]+s[j+1]==0&&s[j]>s[j+1])
return false;
}
return true;
}
ll solve(int last, vector<int> &s, int len, ll curr)
{
if(check(s, len))
return curr;
if(last==len)
return 1e18;
ll res1 = 1e18;
ll res2 = 1e18;
ll res3 = 1e18;
for(int i = last; i<len; i++)
{
res1 = min(res1, solve(last+1, s, len, curr));
if(i<len-1)
{
swap(s[i], s[i+1]);
res2 = min(res2, solve(last+1, s, len, curr+1));
swap(s[i], s[i+1]);
}
if(i>0)
{
swap(s[i], s[i-1]);
res3 = min(res3, solve(last+1, s, len, curr+1));
swap(s[i], s[i-1]);
}
}
return min(min(res1, res2), res3);
}
ll count_swaps(vector<int> s)
{
int n = (int)s.size()/2;
ll res = solve(0, s, 2*n, 0);
return res;
}
# | 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... |