# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
832146 | tranxuanbach | Arranging Shoes (IOI19_shoes) | C++17 | 1096 ms | 114044 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>
using namespace std;
#define isz(a) ((signed)a.size())
using ll = long long;
const int N = 1e5 + 5;
int n;
int a[N];
namespace subtask12{
bool check(){
return n <= 8;
}
map <vector <int>, int> dist;
ll solve(){
queue <pair <int, vector <int>>> qu;
auto transition = [&](int d, const vector <int>& state){
if (not dist.count(state)){
dist[state] = d;
qu.emplace(d, state);
}
};
transition(0, vector <int>(a + 1, a + 2 * n + 1));
while (not qu.empty()){
auto [d, b] = qu.front(); qu.pop();
bool ok = true;
for (int i = 0; i < n; i++){
if (not (b[2 * i] < 0 and b[2 * i] == -b[2 * i + 1])){
ok = false;
break;
}
}
if (ok){
return d;
}
for (int i = 1; i < 2 * n; i++){
swap(b[i - 1], b[i]);
transition(d + 1, b);
swap(b[i - 1], b[i]);
}
}
}
}
ll count_swaps(vector <int> _a){
n = isz(_a) / 2;
for (int i = 1; i <= 2 * n; i++){
a[i] = _a[i - 1];
}
if (subtask12::check()){
return subtask12::solve();
}
}
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... |