Submission #199098

#TimeUsernameProblemLanguageResultExecution timeMemory
199098redaArranging Shoes (IOI19_shoes)C++14
65 / 100
1092 ms2172 KiB
#include<bits/stdc++.h>
#define ll  long long 
#pragma GCC optimize ("Ofast","unroll-loops")
using namespace std;
#define  all(x) x.begin(),x.end()
#define pb push_back
const ll MAXN = 1e5 + 4 ;
long  long count_swaps (vector<int>s)
{
  ll   n = s.size();
  bool  c=1;
      long long  ans = 0 ;
        n=n/2LL;
      for(int i = 0 ;i<n;i++)
      {
        if(s[i]!=-1*s[i+n] || s[i]>0){c=0;break;}
      }
      if(c){
        return (ll)n*(n-1)/2LL;
      }
      for(int i = 0 ;i < s.size();i+=2)
      {
        int j = i+1;
        while(s[i]!=-s[j])
        {
            j++;
        }
        while (j!=i+1)
        {
            swap(s[j],s[j-1]);
            ans++;
            j--;
        }
        if(s[j]<0)
        {
            swap(s[i],s[j]);
            ans++;
        }
      }
      return ans;
  }/*
int main ()
{ 
 vector<int> s ; 
 s.pb(2);
 s.pb(1);
 s.pb(-1);
 s.pb(-2);
 cout<<count_swaps(s)<<endl;
}*/

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i = 0 ;i < s.size();i+=2)
                      ~~^~~~~~~~~~
#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...