#include "books.h"
#include <bits/stdc++.h>
#define lli long long
#define ad push_back
#define fr first
#define sc second
#define MP make_pair
using namespace std;
const int N = 1e6 + 30;
int i1, n;
int col[N], a[N], p[N];
int gp(int x)
{
if(p[x] == x) return x;
return p[x] = gp(p[x]);
}
vector<pair<lli, pair<int, int> > > fp;
lli ans;
int dfs(int v)
{
col[v] = i1;
if(!col[a[v]]) return max(v, dfs(a[v]));
}
long long minimum_walk(vector<int> p, int s)
{
n = p.size();
for(int i = 0; i < n; i++) a[i] = p[i], ans += abs(a[i] - i), ::p[i] = i;
int nx = 0;
for(int i = 0; i < n; i++)
{
if(a[i] == i) continue;
if(!col[i])
{
ans += 2*max(0, (i - nx));
i1++;
nx = max(nx, dfs(i));
}
}
return ans;
}
Compilation message
books.cpp: In function 'int dfs(int)':
books.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
25 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
722 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |