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 <bits/stdc++.h>
#ifdef local
#define debug(...) QQBX(#__VA_ARGS__, __VA_ARGS__)
void QQBX(const char *s) {}
template <typename H, typename ...T> void QQBX(const char *s, const H&h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if(sizeof...(T)) QQBX(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n";
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size();
for(int i = n-1; i >= 0; i--) if(p[i] != i) return i*2;
return 0;
debug(n);
vector<int> loc(n);
for(int i = 0; i < n; i++) loc[p[i]] = i;
int64_t ans = 0;
int fr = 0, bk = n-1;
while(fr < n && p[fr] == fr) ++fr;
while(bk >= 0 && p[bk] == bk) --bk;
if(fr == n) return 0;
int onHand = -1;
while(true) {
while(s < bk) {
int x = p[s];
if(s < x && (onHand==-1 || x > onHand)) {
onHand = x;
p[s] = onHand;
}
}
while(bk >= 0 && p[bk] == bk) --bk;
if(bk == -1) return ans;
while(s > fr) {
int x = p[s];
}
while(fr < n && p[fr] == fr) ++fr;
if(fr == n) return ans;
}
return ans;
}
Compilation message (stderr)
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:45:17: warning: unused variable 'x' [-Wunused-variable]
45 | int x = p[s];
| ^
# | 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... |