제출 #414652

#제출 시각아이디문제언어결과실행 시간메모리
414652hibye1217Arranging Shoes (IOI19_shoes)C++17
50 / 100
1080 ms3112 KiB
#ifndef NOTSUBMIT
#include "shoes.h"
using namespace std;
#endif

int psh(std::vector<int>& s, int st, int ed){
	int res = 0;
	for (int j = st; j > ed; j--){
		swap(s[j], s[j-1]);
		res += 1;
	}
	return res;
}

long long count_swaps(std::vector<int> s) {
	int n = s.size();
	int ans = 0;
	for (int i = 0; i < n; i += 2){
		int p = 0;
		for (int j = i; j < n; j++){
			if (s[j] == -s[i]){ p = j; break; }
		}
		ans += psh(s, p, i+1);
		if (s[i] > s[i+1]){ swap(s[i], s[i+1]); ans += 1; }
	}
	return ans;
}
#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...