#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
#define len(x) ((int)x.size())
int t, n;
vi a, b;
int s;
vi p;
vector<int> adj;
long long minimum_walk(std::vector<int> pp, int ss) {
s = ss;
p = pp;
int n = pp.size();
ll ans=0;
adj.resize(n);
FOR(i,n){
adj[i] = (p[i]);
}
vector<bool> vis(n, 0);
set<int> lop;
FOR(i,n) if(adj[i]!=i) lop.insert(i);
FOR(i,n) ans+=abs(i-adj[i]);
vi cl(n);
FOR(i,n){
cl[i] = 0;
if(adj[i]>i){
FORi(j,i,adj[i]) cl[j] = 1;
i = adj[i]-1;
}
}
vi cr(n);
for(int i=n-1;i>=0;i--){
cr[i] = 0;
if(adj[i]<i){
FORi(j,adj[i]+1, i+1) cr[j] = 1;
i = adj[i]+1;
}
}
FOR(i,n-1){
if(adj[i]==i) continue;
bool ok = true;
if(lop.upper_bound(i)==lop.end()) ok = false;
if(!cl[i] && !cr[i+1]) ok = false;
if(!ok) ans+=2;
//if(!ok) cout<<i<<" ";
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |