Submission #1087671

#TimeUsernameProblemLanguageResultExecution timeMemory
1087671MahmytMArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms352 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl void afterdot(int n){ cout<<setprecision(n)<<fixed; } ll count_swaps(vector<int> s){ if(s.size()==2){ if(s[0]<=0){ return 0; } return 1; } int ans=0; for(int i=0;i<s.size();i++){ if(s[i]>0){ int z=-1*s[i],num=1e9,in; for(int j=0;j<s.size();j++){ if(s[j]==z){ if(num>abs(i-j)){ num=abs(i-j); in=j; } } } if(in>i){ for(int j=i;j<in;j++){ swap(s[j],s[j+1]); ans++; } }else{ for(int j=in;j<i-1;j++){ swap(s[j],s[j+1]); ans++; } } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
shoes.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |    for(int j=0;j<s.size();j++){
      |                ~^~~~~~~~~
shoes.cpp:22:26: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   22 |    int z=-1*s[i],num=1e9,in;
      |                          ^~
#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...