#include "books.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
#include "books.h"
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size();
ll ans = 0;
while (s < n && p[s] == s)
++s,ans += 2;
if (s == n)
return 0;
vi was(n,0);
vector < pii > e;
for (int i = 0;i < n;++i)
if (i != p[i] && !was[i]) {
int cnt = i;
int mx = 0;
do {
was[cnt] = 1;
smax(mx,cnt);
cnt = p[cnt];
} while (cnt != i);
e.pb(mp(i,mx));
}
for (int i = 0;i < n;++i)
ans += abs(i - p[i]);
int k = e.size();
int j = 0;
for (int i = 0;i + 1 < k;++i)
if (e[i + 1].fi > e[i].se)
ans += 2;
return ans;
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:41:6: warning: unused variable 'j' [-Wunused-variable]
int j = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
616 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
2 ms |
616 KB |
Output is correct |
14 |
Correct |
2 ms |
616 KB |
Output is correct |
15 |
Correct |
2 ms |
616 KB |
Output is correct |
16 |
Correct |
2 ms |
616 KB |
Output is correct |
17 |
Correct |
2 ms |
616 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
616 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
2 ms |
616 KB |
Output is correct |
14 |
Correct |
2 ms |
616 KB |
Output is correct |
15 |
Correct |
2 ms |
616 KB |
Output is correct |
16 |
Correct |
2 ms |
616 KB |
Output is correct |
17 |
Correct |
2 ms |
616 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
19 |
Correct |
2 ms |
616 KB |
Output is correct |
20 |
Correct |
2 ms |
616 KB |
Output is correct |
21 |
Correct |
2 ms |
616 KB |
Output is correct |
22 |
Incorrect |
2 ms |
616 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '1128' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
616 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
2 ms |
616 KB |
Output is correct |
14 |
Correct |
2 ms |
616 KB |
Output is correct |
15 |
Correct |
2 ms |
616 KB |
Output is correct |
16 |
Correct |
2 ms |
616 KB |
Output is correct |
17 |
Correct |
2 ms |
616 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
19 |
Correct |
2 ms |
616 KB |
Output is correct |
20 |
Correct |
2 ms |
616 KB |
Output is correct |
21 |
Correct |
2 ms |
616 KB |
Output is correct |
22 |
Incorrect |
2 ms |
616 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '1128' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
616 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3060' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
616 KB |
Output is correct |
12 |
Correct |
2 ms |
616 KB |
Output is correct |
13 |
Correct |
2 ms |
616 KB |
Output is correct |
14 |
Correct |
2 ms |
616 KB |
Output is correct |
15 |
Correct |
2 ms |
616 KB |
Output is correct |
16 |
Correct |
2 ms |
616 KB |
Output is correct |
17 |
Correct |
2 ms |
616 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
19 |
Correct |
2 ms |
616 KB |
Output is correct |
20 |
Correct |
2 ms |
616 KB |
Output is correct |
21 |
Correct |
2 ms |
616 KB |
Output is correct |
22 |
Incorrect |
2 ms |
616 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '1128' |
23 |
Halted |
0 ms |
0 KB |
- |