Submission #144833

#TimeUsernameProblemLanguageResultExecution timeMemory
144833DanerZeinArranging Shoes (IOI19_shoes)C++14
10 / 100
1087 ms1960 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
  int c=0;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]>0){
	int id;
	for(int j=i+1;j<s.size();j++){
	  if(s[j]<0){
	    id=j;
	    break;
	  }
	}
	for(int j=id;j>i;j--){
	  c++;
	  swap(s[j],s[j-1]);
	}
      }
    }
    else{
      if(s[i]<0){
	int id;
	for(int j=i+1;j<s.size();j++){
	  if(s[j]>0){
	    id=j;
	    break;
	  }
	}
	for(int j=id;j>i;j--){
	  c++;
	  swap(s[j],s[j-1]);
	}
      }
    }
  }
  return c;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:6:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:10:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=i+1;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:25:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=i+1;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:24:6: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int id;
      ^~
shoes.cpp:9:6: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int id;
      ^~
#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...