Submission #145625

#TimeUsernameProblemLanguageResultExecution timeMemory
145625chubyxdxdArranging Shoes (IOI19_shoes)C++14
10 / 100
1084 ms3320 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long long count_swaps(std::vector<int> s) {
  ll tam=s.size();
  if(tam/2==1){
    if(s[0]<0){
      return 0;
    }
    else{
      return 1;
    }
  }
  ll hi=0;
  ll h,c=0,f,aux;
  for(int i=0;i<s.size();i++){
    /* for(int j=0;j<s.size();j++){
        cout<<s[j]<<" ";
	}
	cout<<endl;*/
    if(i==0){
        for(int j=i;j<s.size();j++){
            if(s[j]<0){
                h=j;
                c+=abs(i-j);
                break;
            }
        }
        if(h==i){
            continue;
        }
        for(int j=h;j>i;j--){
            aux=s[j-1];
            s[j-1]=s[j];
            s[j]=aux;
        }
      continue;
    }
    if(i%2==0){
      for(int j=i;j<s.size();j++){
        if(s[j]<0){
            h=j;
            c+=abs(i-j);
            break;
        }
      }
      if(h==i){
        continue;
      }
      for(int j=h;j>i;j--){
        aux=s[j-1];
        s[j-1]=s[j];
        s[j]=aux;
      }
    }
    else{
      ll k=s[i-1]*-1;
      for(int j=i;j<s.size();j++){
            if(s[j]==k){
            h=j;
            c+=abs(i-j);
            break;
        }
      }
      if(h==i){
      continue;
      }
      for(int j=h;j>i;j--){
        aux=s[j-1];
        s[j-1]=s[j];
        s[j]=aux;
      }
    }
  }
  return c;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:18:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=i;j<s.size();j++){
                     ~^~~~~~~~~
shoes.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=i;j<s.size();j++){
                   ~^~~~~~~~~
shoes.cpp:60:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=i;j<s.size();j++){
                   ~^~~~~~~~~
shoes.cpp:16:6: warning: unused variable 'hi' [-Wunused-variable]
   ll hi=0;
      ^~
shoes.cpp:17:12: warning: unused variable 'f' [-Wunused-variable]
   ll h,c=0,f,aux;
            ^
shoes.cpp:31:9: warning: 'h' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(h==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...