#include <cstdio>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
#include "books.h"
int n,v[1000005];
using namespace std;
long long minimum_walk(std::vector<int> p, int s)
{
n=p.size();
int i;
for (i=1; i<=n; i++)
{
v[i]=p[i-1]+1;
}
int sum=0,acum=s+1;
for (i=1; i<=n; i++)
{
if (v[i]!=i)
{
int ceam;
sum=sum+abs(acum-i);
acum=i;
ceam=v[i];
v[i]=0;
while (v[ceam]&&ceam!=acum)
{
sum=sum+abs(acum-ceam);
acum=ceam;
swap(v[ceam],ceam);
}
sum=sum+abs(acum-ceam);
acum=ceam;
v[ceam]=ceam;
}
}
sum=sum+abs(acum-(s+1));
return sum;
}
#ifdef HOME
int main()
{
ifstream cin("date.in");
ofstream cout("date.out");
int n, s;
cin>>n>>s;
vector<int> p((unsigned) n);
for(int i = 0; i < n; i++)
{
cin>>p[i];
}
long long res = minimum_walk(p, s);
cout<<res;
return 0;
}
#endif // HOME
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
304 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4728' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 |
Halted |
0 ms |
0 KB |
- |