# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244811 | crossing0ver | Arranging Shoes (IOI19_shoes) | C++17 | 5 ms | 512 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
#include "shoes.h"
using namespace std;
ll count_swaps(vector<int> a) {
int n = a.size();
ll ans = 0;
vector< vector<vector<int>> > v(2,vector< vector<int> >(n+1));
for (int i = 0;i < n; i++) {
if (a[i] < 0) v[1][-a[i]].push_back(i);
else v[0][a[i]].push_back(i);
}
vector<int> vis(n,1);
for (int i = 1; i <= n; i++)
for (int t = 0; t < 2; t++)
reverse(v[t][i].begin(),v[t][i].end());
for (int i = 0; i < n;i++) {
if (vis[i] == 0) continue;
int x = a[i];
int val = abs(x);
int t = (x < 0 ? 0 : 1);
int ps = v[t][x].back();
vis[i] = 0;
v[t][x].pop_back();
v[!t][x].pop_back();
for (int j = i + 1; j <= ps; j++)
ans += vis[j];
if (t == 0) ans++;
vis[ps] = 0;
}
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... |