제출 #422662

#제출 시각아이디문제언어결과실행 시간메모리
422662MeGustaElArroz23Arranging Shoes (IOI19_shoes)C++14
10 / 100
29 ms5176 KiB
#include "shoes.h"
#include <cstdio>
#include <cassert>

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<bool,bool> pbb;
typedef vector<pbb> vbb;
typedef pair<int,int> pii;
typedef vector<pii> vii;

const ll INF=1000000001;

bool samesize(vi v){
	for (int x:v){
		if (abs(v[x])!=abs(v[0])) return false;
	}
	return true;
}

long long count_swaps(std::vector<int> v) {
	int n=v.size()/2;
	ll sol=0;
	if (samesize(v)){
		ll balance;
		for (int x:v){
			if (x<0){
				if (balance>0){
					sol+=balance;
				}
				balance--;
			}
			else{
				if (balance<-1) sol+=-balance-1;
				balance++;
			}
		}
		return sol;
	}
	for (int i=0;i<n;i++){
		vbb porver(n+1,pbb{true,true});
		vii dondevisto(n+1);
		for (int j=2*i;j<2*n;j++){
			int x=v[j];
			if (x<0){
				x=-x;
				if (porver[x].first){
					porver[x].first=false;
					dondevisto[x].first=j;
				}
			}
			else{
				if (porver[x].second){
					porver[x].second=false;
					dondevisto[x].second=j;
				}
			}
			if (porver[x]==pbb{false,false}){
				for (int h=dondevisto[x].first;h>2*i;h--){
					sol++;
					swap(v[h],v[h-1]);
				}
				if (dondevisto[x].second<dondevisto[x].first) dondevisto[x].second++;
				for (int h=dondevisto[x].second;h>2*i+1;h--){
					sol++;
					swap(v[h],v[h-1]);
				}
				break;
			}
		}
	}
	return sol;
}
#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...