Submission #722937

#TimeUsernameProblemLanguageResultExecution timeMemory
722937LittleCubeArranging Shoes (IOI19_shoes)C++17
10 / 100
60 ms13520 KiB
#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

vector<int> p[100005][2];
int a[200005];

ll count_swaps(vector<int> s) 
{
	ll ans = 0;
	int N = s.size() / 2;
	for (int i = 0; i < N * 2; i++)
	{
		if(s[i] < 0)
			p[-s[i]][1].emplace_back(i);
		else
			p[s[i]][0].emplace_back(i);
	}
	for (int i = 1; i <= N; i++)
		for (int j = 0; j < p[i][0].size(); j++)
			a[min(p[i][0][j], p[i][1][j])] = 1;
	for (int i = 1; i < 2 * N; i++)
		a[i] += a[i - 1];
	for (int i = 1; i <= N; i++)
		for (int j = 0; j < p[i][0].size(); j++)
		{	
			if(p[i][1][j] > p[i][0][j])
				ans += 2, swap(p[i][1][j], p[i][0][j]);
			ll l = a[p[i][0][j] - 1] - a[p[i][1][j]], r = p[i][0][j] - 1 - p[i][1][j] - l;
			ans += abs(r - l);
			ans += 4 * min(l, r);
		}
	return ans / 2;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int j = 0; j < p[i][0].size(); j++)
      |                   ~~^~~~~~~~~~~~~~~~
shoes.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for (int j = 0; j < p[i][0].size(); j++)
      |                   ~~^~~~~~~~~~~~~~~~
#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...