Submission #1047398

#TimeUsernameProblemLanguageResultExecution timeMemory
1047398NotLinuxArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms424 KiB
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
const long long inf = 1e18 + 7;
long long count_swaps(vector<int> s) {
	int n = sz(s) / 2;
	long long ans = inf;
	// cout << "n : " << n << endl;
	// for(auto itr : s)cout << itr << " ";cout << endl;
	if(n == 1){// 10 pts - n = 1
		ans = 0;
		if(s[0] > 0)ans++;
		return ans;
	}
	if(n <= 8){// 20 pts - n <= 8
		vector < int > shoes;
		for(auto itr : s)if(itr > 0)shoes.push_back(itr);
		// cout << "shoes : ";for(auto itr : shoes)cout << itr << " ";cout << endl;
		sort(all(shoes));
		vector < int > perm(n);
		iota(all(perm) , 0);
		do{	
			vector < int > tmp = s;
			long long locans = 0;
			vector < int > news;
			for(auto itr : perm){
				news.push_back(-shoes[itr]);
				news.push_back(shoes[itr]);
			}
			for(int i = 0;i<2*n;i++){
				int cur = i;
				while(tmp[cur] != news[i])cur++;
				locans += cur - i;
				int tmpe = tmp[i];
				for(int j = i;j<cur;j++){
					tmp[j] = tmp[j+1];
				}	
				tmp[cur] = tmpe;
			}
			// cout << "news : ";for(auto itr : news)cout << itr << " ";cout << endl;
			// cout << "locans : " << locans << endl;
			ans = min(ans , locans);
		} while(next_permutation(all(perm)));
		return ans;
	}
	// set < int > ste;
	// for(auto itr : s){
	// 	ste.insert(abs(itr));
	// }
	// if(sz(ste) == 1){// 20 pts - all shoe sizes are same

	// }
	// else{// 15 pts - first n are left , rest are right and i = i+n

	// }
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
#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...