Submission #144528

#TimeUsernameProblemLanguageResultExecution timeMemory
144528MohamedAhmed04Arranging Shoes (IOI19_shoes)C++14
50 / 100
1082 ms2040 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std ;

long long count_swaps(vector<int> v) 
{
	int ans = 0 ;
	for(int i = 0 ; i < v.size() ; ++i)
	{
		if(i&1)
			continue ;
		int idx ;
		for(int j = i+1 ; j < v.size() ; ++j)
		{
			if(v[j] == -v[i])
			{
				idx = j ;
				break ;
			}
		}
		for(int j = idx-1 ; j > i ; --j)
		{
			swap(v[j], v[j+1]) ;
			ans++ ;
		}
		if(v[i] > 0)
			swap(v[i], v[i+1]), ans++ ;
	}
	return ans ;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < v.size() ; ++i)
                  ~~^~~~~~~~~~
shoes.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = i+1 ; j < v.size() ; ++j)
                     ~~^~~~~~~~~~
shoes.cpp:13:7: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int idx ;
       ^~~
#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...