Submission #1029336

#TimeUsernameProblemLanguageResultExecution timeMemory
1029336enderArranging Shoes (IOI19_shoes)C++14
25 / 100
15 ms4408 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;

long long count_swaps(std::vector<int> s) {

	long long ans = 0;
	int cl = 0, cr = 0;
	vector<int> l, r;

	for(int i = 0; i < s.size(); ++i){

		if(s[i] < 0) l.push_back(i);
		else r.push_back(i);

	}

	for(int i = 0; i < s.size(); ++i){

		if(i%2 == 0){

			if(s[i] > 0){

				ans += l[cl] - i;
				swap(s[i], s[l[cl]]);
				cr++;
			} 

			cl++;

		}else {

			if(s[i] < 0){

				ans += r[cr] - i;
				swap(s[i], s[r[cr]]);	
				cl++;
			} 
			
			cr++;

		}

	}

	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  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...