# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158249 | reda | Arranging Shoes (IOI19_shoes) | C++14 | 1078 ms | 1912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
long long count_swaps (vector<int>s)
{
int n = s.size();
bool c=1;
long long ans = 0 ;
for(int i = 0 ;i<=n/2;i++)
{
if(s[i]!=-s[2*i-1]){c=0;break;}
}
n=n/2LL;
if(c)return 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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |