# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
601789 | Minindu2006 | Arranging Shoes (IOI19_shoes) | C++14 | 1085 ms | 12436 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 "shoes.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll count_swaps(vector<int> s)
{
ll n = s.size() / 2;
if (n == 1)
return s[0] > 0;
set<int> st;
int isb4 = 1;
for (int i = 0; i < n; i++)
{
if (s[i] != -s[i + n] || s[i] > 0)
{
isb4 = 0;
break;
}
}
if (isb4)
return n * (n - 1) / 2;
for(int i=0;i<2*n;i++)
st.insert(s[i]);
if (st.size() == 2)
{
vector<int> l;
for (int i = 0; i < 2 * n; i++)
if (s[i] < 0)
l.push_back(i);
ll ans = 0, j = 0;
for (int i = 0; i < 2 * n; i += 2)
ans += abs(i - l[j]), j++;
return ans;
}
ll pos = 0, ans = 0;
while (pos < 2 * n)
{
if (s[pos] > 0)
{
int i;
for (i = pos + 1; i < 2 * n; i++)
if (s[i] == -s[pos])
break;
int num = s[i];
s.erase(s.begin() + i);
s.insert(s.begin() + pos, num);
ans += (i - pos);
}
else if (s[pos] + s[pos + 1] != 0)
{
int i;
for (i = pos + 2; i < 2 * n; i++)
if (s[i] == -s[pos])
break;
int num = s[i];
s.erase(s.begin() + i);
s.insert(s.begin() + pos + 1, num);
ans += (i - pos - 1);
}
// cout << s[pos] << " " << s[pos + 1] << '\n';
pos += 2;
}
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... |