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 "shoes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long count_swaps(vector<int> s)
{
int n = s.size() / 2;
if (n == 1)
{
if (s[0] > 0)
return 1;
return 0;
}
int pt0 = 0, pt1 = 0;
while(pt0 < 2 * n && s[pt0] > 0)
pt0 ++;
while(pt1 < 2 * n && s[pt1] > 0)
pt1 ++;
ll ans = 0;
for (int i = 0; i < 2 * n; i ++)
{
///cout << i << " " << pt0 << " " << pt1 << endl;
if (i % 2 == 0)
{
if (pt0 == i)
{
pt0 ++;
}
else
{
ans = ans + (ll)(pt0 - i);
swap(s[pt0], s[i]);
pt1 ++;
}
}
else
{
if (pt1 == i)
{
pt1 ++;
}
else
{
pt0 ++;
ans = ans + (ll)(pt1 - i);
swap(s[pt1], s[i]);
}
}
while(pt0 < 2 * n && s[pt0] > 0)
pt0 ++;
while(pt1 < 2 * n && s[pt1] > 0)
pt1 ++;
}
return ans;
}
# | 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... |