| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 332323 | blue | Arranging Shoes (IOI19_shoes) | C++17 | 28 ms | 3180 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 <vector>
using namespace std;
long long count_swaps(vector<int> S)
{
int n = S.size()/2;
return (n-1)*n/2;
long long res = 0;
vector<int> left[n+1], right[n+1];
vector<int> othershoe(2*n, -1);
for(int i = 0; i < 2*n; i++)
{
if(S[i] < 0) left[-S[i]].push_back(i);
else right[S[i]].push_back(i);
}
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < left[i].size(); j++)
{
if(left[i][j] < right[i][j]) othershoe[left[i][j]] = right[i][j];
else
{
othershoe[right[i][j]] = left[i][j];
res++;
}
}
}
vector<int> leftshift(2*n, 0);
long long lshift = 0;
for(int i = 0; i < 2*n; i++)
{
lshift += leftshift[i];
leftshift[othershoe[i] + 1]++;
res += (long long)(othershoe[i] - i - 1 - lshift);
}
return res;
}
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... | ||||
