제출 #559344

#제출 시각아이디문제언어결과실행 시간메모리
559344LastRoninArranging Shoes (IOI19_shoes)C++14
10 / 100
4 ms4948 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const ll N = 2e5;

ll n;
vector<ll> st, ex[N];

long long count_swaps(vector<int> s) {
	n = s.size();
	ll pos = 0;
	for(auto u : s) {
		if(u < 0) {
			st.pb(pos++);
		}
		else {
			ex[u].pb(pos++);
		}
	}
	for(int j = 1; j <= n; j++) {
		reverse(ex[j].begin(), ex[j].end());
	}
	ll ans = 0;
	for(int j = 0; j < n; j += 2) {
		ll z = -1;
		for(int i = j; i < n; i++) {
			if(s[i] < 0) {
				z = i;
				break;
			}
		}
		for(int i = z; i > j; i--)
			swap(s[i], s[i - 1]), ans++;
		z = -1;
		for(int i = j + 1; i < n; i++) {
			if(s[i] == -s[j]) {
				z = i;				
			}
		}
		for(int i = z; i > j + 1; i--) 
			swap(s[i], s[i - 1]), ans++;
	}
	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...