제출 #1273915

#제출 시각아이디문제언어결과실행 시간메모리
1273915almazArranging Shoes (IOI19_shoes)C++20
0 / 100
724 ms1114112 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,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){
			int res = INF;
			for(int j = i;j < n;j++){
				if(a[j] < 0 && 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 && 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 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...