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"
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define N 100
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) ll(a.size())
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
ll n;
long long minimum_walk(vector<int> p, int s) {
n = p.size();
int x = s, y = -1;
ll ans = 0;
for(ll i = 0; i < n; i++) {
if(y <= i && y != -1) {
ans += abs(x-y);
x = y;
swap(p[y], y);
}
if(i == n-1) {
ans += abs(x);
break;
}
ans += abs(i+1-x);
if(y == -1 && p[x] != i) {
y = p[x];
swap(p[x], p[i+1]);
p[x] = -1;
}
else swap(y, p[i+1]);
x = i+1;
}
return ans;
}
# | 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... |