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 "books.h"
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
/*
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int>tr;
*/
int aux,x,pos,curr;
ll minimum_walk(vector<int>p, int s)
{
int n = sz(p);
vector<int>vec;
for(int i = 0;i < n;i++)
{
vec.pb(i);
}
int ans = 1e9;
vector<int>aux;
do
{
aux = p;
x = 0;
pos = 0;
curr = -1;
for(auto it : vec)
{
int idx = -1;
for(int i = 0;i < sz(aux);i++)
{
if(aux[i] == it) idx = i;
}
if(idx != -1)
{
x += abs(idx - pos);
pos = idx;
aux[pos] = curr;
curr = it;
}
x += abs(pos - it);
curr = aux[it];
aux[it] = it;
pos = it;
}
ans = min(ans,x + pos);
}while(next_permutation(vec.begin(),vec.end()));
return ans;
}
Compilation message (stderr)
books.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# | 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... |