#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001];
vector <pair <int, pair <int, int>>> e;
vector <int> ve[1000001];
long long minimum_walk(vector <int> p, int s){
int x=0,n=p.size();
long long d=0;
for (int i=0;i<n;i++){
if (!vis[i]){
int x=i;
while (true){
vis[x]=1;
ve[i].push_back(x);
d+=abs(x-p[x]);
x=p[x];
if (x==i)
break;
}
}
}
vector <pair <int, int>> tmp;
for (int i=0;i<n;i++){
if (ve[i].empty()||(ve[i].size()==1&&i!=s))
continue;
sort(ve[i].begin(),ve[i].end());
tmp.push_back({ve[i][0],ve[i].back()});
}
sort(tmp.begin(),tmp.end());
int cur=0;
for (auto [l,r]:tmp){
x+=max(l-cur,0);
cur=r;
}
return x*2+d;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
5 ms |
25208 KB |
Output is correct |
3 |
Correct |
5 ms |
25176 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25180 KB |
Output is correct |
6 |
Correct |
5 ms |
25180 KB |
Output is correct |
7 |
Correct |
5 ms |
25236 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
5 ms |
25180 KB |
Output is correct |
10 |
Correct |
5 ms |
25176 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25180 KB |
Output is correct |
13 |
Correct |
5 ms |
25184 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
15 |
Correct |
5 ms |
25180 KB |
Output is correct |
16 |
Correct |
5 ms |
25180 KB |
Output is correct |
17 |
Correct |
5 ms |
25180 KB |
Output is correct |
18 |
Correct |
5 ms |
25236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
5 ms |
25208 KB |
Output is correct |
3 |
Correct |
5 ms |
25176 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25180 KB |
Output is correct |
6 |
Correct |
5 ms |
25180 KB |
Output is correct |
7 |
Correct |
5 ms |
25236 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
5 ms |
25180 KB |
Output is correct |
10 |
Correct |
5 ms |
25176 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25180 KB |
Output is correct |
13 |
Correct |
5 ms |
25184 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
15 |
Correct |
5 ms |
25180 KB |
Output is correct |
16 |
Correct |
5 ms |
25180 KB |
Output is correct |
17 |
Correct |
5 ms |
25180 KB |
Output is correct |
18 |
Correct |
5 ms |
25236 KB |
Output is correct |
19 |
Correct |
5 ms |
25180 KB |
Output is correct |
20 |
Correct |
5 ms |
25176 KB |
Output is correct |
21 |
Correct |
5 ms |
25180 KB |
Output is correct |
22 |
Incorrect |
5 ms |
25180 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '2104' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
5 ms |
25208 KB |
Output is correct |
3 |
Correct |
5 ms |
25176 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25180 KB |
Output is correct |
6 |
Correct |
5 ms |
25180 KB |
Output is correct |
7 |
Correct |
5 ms |
25236 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
5 ms |
25180 KB |
Output is correct |
10 |
Correct |
5 ms |
25176 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25180 KB |
Output is correct |
13 |
Correct |
5 ms |
25184 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
15 |
Correct |
5 ms |
25180 KB |
Output is correct |
16 |
Correct |
5 ms |
25180 KB |
Output is correct |
17 |
Correct |
5 ms |
25180 KB |
Output is correct |
18 |
Correct |
5 ms |
25236 KB |
Output is correct |
19 |
Correct |
5 ms |
25180 KB |
Output is correct |
20 |
Correct |
5 ms |
25176 KB |
Output is correct |
21 |
Correct |
5 ms |
25180 KB |
Output is correct |
22 |
Incorrect |
5 ms |
25180 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '2104' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
25432 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4072' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25176 KB |
Output is correct |
2 |
Correct |
5 ms |
25208 KB |
Output is correct |
3 |
Correct |
5 ms |
25176 KB |
Output is correct |
4 |
Correct |
5 ms |
25180 KB |
Output is correct |
5 |
Correct |
5 ms |
25180 KB |
Output is correct |
6 |
Correct |
5 ms |
25180 KB |
Output is correct |
7 |
Correct |
5 ms |
25236 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
5 ms |
25180 KB |
Output is correct |
10 |
Correct |
5 ms |
25176 KB |
Output is correct |
11 |
Correct |
5 ms |
25180 KB |
Output is correct |
12 |
Correct |
5 ms |
25180 KB |
Output is correct |
13 |
Correct |
5 ms |
25184 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
15 |
Correct |
5 ms |
25180 KB |
Output is correct |
16 |
Correct |
5 ms |
25180 KB |
Output is correct |
17 |
Correct |
5 ms |
25180 KB |
Output is correct |
18 |
Correct |
5 ms |
25236 KB |
Output is correct |
19 |
Correct |
5 ms |
25180 KB |
Output is correct |
20 |
Correct |
5 ms |
25176 KB |
Output is correct |
21 |
Correct |
5 ms |
25180 KB |
Output is correct |
22 |
Incorrect |
5 ms |
25180 KB |
3rd lines differ - on the 1st token, expected: '2082', found: '2104' |
23 |
Halted |
0 ms |
0 KB |
- |