#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ar array
const int MOD = 1e9 + 7,INF = 1e9, N = 2e5 + 5;
int ans(vector <int> a , int sum){
int n = a.size();
for(int i = 0;i < n;i += 2){
if(a[i] < 0 && a[i + 1] > 0 && abs(a[i]) == a[i + 1]) continue;
if(a[i] > 0 && a[i + 1] < 0){
sum++;
swap(a[i] , a[i + 1]);
}
if(a[i] < 0 && a[i + 1] > 0 && abs(a[i]) == a[i + 1]) continue;
if(a[i] > 0 && a[i + 1] > 0){
int res = INF;
for(int j = i;j < n;j++){
if(a[j] < 0 && abs(a[j]) == a[i + 1]){
swap(a[i] , a[j]);
res = min(res , ans(a , sum + 1));
swap(a[i] , a[j]);
}
}
return res;
}
if(a[i] < 0){
int res = INF;
for(int j = i;j < n;j++){
if(a[j] < 0 && abs(a[j]) == a[i]){
swap(a[i + 1] , a[j]);
res = min(res , ans(a , sum + 1));
swap(a[i + 1] , a[j]);
}
}
return res;
}
}
return sum;
}
long long count_swaps(std::vector<int> s) {
return ans(s , 0);
}
# | 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... |