Submission #146069

#TimeUsernameProblemLanguageResultExecution timeMemory
146069DanerZeinArranging Shoes (IOI19_shoes)C++14
15 / 100
32 ms2040 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; int c,i,j,id; long long count_swaps(std::vector<int> s) { bool sw=0; int j=s.size()/2; for(int i=0;i<s.size()/2;i++){ if(s[i]*(-1)!=s[j]){ sw=1; break; } j++; } if(sw==0){ long long acum=0; for(int i=1;i<s.size()/2;i++){ acum+=i; } return acum; } else{ c=0; for(int i=0;i<s.size();i+=2){ /* for(int j=0;j<s.size();j++){ cout<<s[j]<<" "; } cout<<endl;*/ if(s[i]>0){ int shoes=s[i],id; for(int j=i+1;j<s.size();j++){ if(s[j]==shoes*(-1)){ id=j; break; } } for(int j=id;j>i;j--){ swap(s[j],s[j-1]); c++; } } else{ if(s[i+1]!=s[i]*(-1)){ int id,shoes=s[i]*(-1); for(int j=i+1;j<s.size();j++){ if(s[j]==shoes){ id=j; break; } } for(int j=id;j>i+1;j--){ swap(s[j],s[j-1]); c++; } } } } 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()/2;i++){
               ~^~~~~~~~~~~
shoes.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<s.size()/2;i++){
                 ~^~~~~~~~~~~
shoes.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i+=2){
               ~^~~~~~~~~
shoes.cpp:31:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=i+1;j<s.size();j++){
                     ~^~~~~~~~~
shoes.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=i+1;j<s.size();j++){
                ~^~~~~~~~~
shoes.cpp:44:6: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int id,shoes=s[i]*(-1);
      ^~
shoes.cpp:30:22: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
       int shoes=s[i],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...