# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199097 | reda | Arranging Shoes (IOI19_shoes) | C++14 | 40 ms | 1916 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>
#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]){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(1);
s.pb(2);
s.pb(3);
s.pb(-1);
s.pb(-2);
s.pb(-3);
cout<<count_swaps(s)<<endl;
}
*/
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... |