Submission #701114

#TimeUsernameProblemLanguageResultExecution timeMemory
701114mychecksedadArranging Shoes (IOI19_shoes)C++17
10 / 100
73 ms71208 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

long long count_swaps(vector<int> s) {
	long long ans = 0, c = 0;
	deque<int> pos[s.size() / 2 + 1];
	vector<int> pref(s.size());
	for(int i = 0; i < s.size(); ++i){
		if(i>0) pref[i] = pref[i-1];
		if(s[i] < 0){
			ans += abs(i - 2*c);
			pos[abs(s[i])].pb(2*c+1);
			c++;
			pref[i]++;
		}
	}
	for(int i = 0; i < s.size(); ++i){
		if(s[i] > 0){
			ans += abs(i - pos[s[i]].front()) + (i+2)/2 - pref[i];
			pos[s[i]].pop_front();
		}
	}

	return ans/2;
}

Compilation message (stderr)

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