Submission #810194

#TimeUsernameProblemLanguageResultExecution timeMemory
810194Sohsoh84Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms300 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pll;

#define X		first
#define Y		second
#define sep		' '

map<int, vector<pll>> mp;

ll count_swaps(vector<int> vec) {
	ll ans = 0;
	for (int i = 0; i < int(vec.size()); i++)
		mp[abs(vec[i])].push_back({i, int(vec[i] > 0)});

	for (auto [_, e] : mp) {
		vector<pll> vec;
		for (auto [x, y] : e) {
			if (!vec.empty() && y != vec.back().Y) {
				ans += x - vec.back().X - 1 + (y ^ 1);
				vec.pop_back();
			} else vec.push_back({x, y});
		}
	}

	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...