Submission #766298

#TimeUsernameProblemLanguageResultExecution timeMemory
766298LudisseyArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms300 KiB
#include "shoes.h"
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <vector>
#include <fstream>
#include <bitset>
#include <tuple>
#include <cmath>
#include <cstdint>
#include <stack>
#include <cassert>
#include <cstdio>
#include <queue>
#include <iterator>
#include <iomanip>
#include <algorithm>
#include <sstream> 

#define INF  9223372036854775801
#define int long long
#define double long double

#define MOD(a) ((a) % 1000000007  + 1000000007 ) % 1000000007
#define F first
#define caseOut(t) cout << "Case " << t << ": "; 
#define S second
#define USACO_SETUP() ifstream cin("paint.in"); ofstream cout("paint.out");
#define SETUP() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

long long count_swaps(std::vector<signed> s) {
	vector<bool> inorder;
	int n = s.size();
	vector<pair<int,bool>> a(n);
	int sum = 0;
	int i = 0;
	for (int i = 0; i < n; i++)
	{
		a[i] = { s[i],a[i].second };
		if (i<n-1 && s[i] == -s[i + 1] && s[i] < 0) {
			a[i].second = true;
			a[i+1].second = true;
		}
	}
	while(i<n)
	{
		if (a[i].second) {
			i++;
			continue;
		}
		int indx = -1;
		for (int u = i+1; u < n; u++)
		{
			if (a[u].second == false && a[u].first == -a[i].first) {
				indx = u;
				break;
			}
		}
		if (indx == -1) break;
		int targ = (indx / 2) * 2;
		if (a[i].first % 2 != 0) targ++;
		int ad = 1;
		int v = -1;
		if (i < indx) {
			for (v = i; v < n-1; v++)
			{
				if (v < n - 1 && a[v].first<0 && a[v + 1].first == -a[v].first) break;
				else if (v > 0 && a[v-1].first == -a[v].first) break;
				sum++;
				swap(a[v], a[v + 1]);
				ad = 0;
			}
		}
		else {
			for (v = i; v > 0; v--)
			{
				if (v < n - 1 && a[v].first < 0 && a[v + 1].first == -a[v].first) break;
				else if (v > 0 && a[v - 1].first == -a[v].first) break;
				sum++;
				swap(a[v], a[v - 1]);
			}
		}
		if (v < n - 1 && a[v].first < 0 && a[v + 1].first == -a[v].first) a[v].second = a[v + 1].second = true;
		else a[v].second = a[v - 1].second = true;
		i += ad;
	}
	return sum;
}
#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...