Submission #144835

#TimeUsernameProblemLanguageResultExecution timeMemory
144835DanerZeinArranging Shoes (IOI19_shoes)C++14
10 / 100
1075 ms2680 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
  vector<int> r;
  r.resize(s.size());
  int x=abs(s[0]);
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      r[i]=x*(-1);
    }
    else{
      r[i]=x;
    }
  }
  int c=0;
  for(int i=0;i<s.size();i++){
    if(r==s){
      break;
    }
    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:8:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:24:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=i+1;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=i+1;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:38:6: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int id;
      ^~
shoes.cpp:23: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...