Submission #1273936

#TimeUsernameProblemLanguageResultExecution timeMemory
1273936almazArranging Shoes (IOI19_shoes)C++20
0 / 100
1 ms340 KiB
#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, N = 2e5 + 5;

long long INF = 1e18;

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){
			long long 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 , 1ll * ans(a , sum + 1));
					swap(a[i] , a[j]);
				} 
			}
			return res;
		}
		if(a[i] < 0){
			long long res = INF;
			for(int j = i;j < n;j++){
				if(a[j] > 0 && a[j] == abs(a[i])){
					swap(a[i + 1] , a[j]);
					res = min(res , 1ll * ans(a , sum + 1));
					swap(a[i + 1] , a[j]);
				} 
			}
			return res;
		}
	}
	return sum;
}

long long count_swaps(std::vector<int> s) {
	int n = s.size();
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(s[i] == s[i + 1]){
			ans++;
			i++;
		}
	}
	return ans / 2;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...