#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int in[nmax],out[nmax];
long long minimum_walk(vector<int> p, int s)
{
int n=p.size();
while(n-1>s&&p[n-1]==n-1){p.pop_back();n--;}
vector<int> help={};
int where=0;
for(where=0;where<s;where++)
{
if(p[where]!=where)break;
}
for(int i=where;i<n;i++)
help.push_back(p[i]-where);
p=help;
n=p.size();
if(n==0)return 0;
for(int i=0;i<n;i++)
if(i!=p[i])
{
if(i<p[i])
for(int j=i;j<p[i];j++)
out[j]++,in[j+1]++;
else
for(int j=i;j>p[i];j--)
out[j]++,in[j-1]++;
}
/*
for(int i=0;i<n;i++)
cout<<in[i]<<" "<<out[i]<<endl;
*/
int maxi=0;
for(int i=0;i<n;i++)
{
maxi=max(maxi,p[i]);
if(i==maxi)
{
if(i!=n-1)
{
in[i]++;
out[i]++;
in[i+1]++;
out[i+1]++;
}
maxi=0;
}
}
for(int i=1;i<n;i++)
{
if(in[i-1]<out[i-1])
{
out[i]+=out[i-1]-in[i-1];
in[i-1]=out[i-1];
}
else//in[i-1]>out[i-1]
{
in[i]+=in[i-1]-out[i-1];
out[i-1]=in[i-1];
}
}
assert(in[n-1]==out[n-1]);
long long ans=0;
for(int i=0;i<n;i++)
{
ans=ans+in[i]+out[i];
}
return ans/2;
}
/*
int main()
{
//cout<<minimum_walk({0,2,1,3},2)<<endl;
//cout<<minimum_walk({0, 2, 3, 1}, 0)<<endl;
//cout<<minimum_walk({1,0,3,2}, 0)<<endl;
//cout<<minimum_walk({2,3,0,1}, 0)<<endl;
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
552 KB |
Output is correct |
12 |
Correct |
3 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
552 KB |
Output is correct |
12 |
Correct |
3 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
3 ms |
620 KB |
Output is correct |
21 |
Correct |
3 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
728 KB |
Output is correct |
25 |
Correct |
2 ms |
728 KB |
Output is correct |
26 |
Correct |
2 ms |
728 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
3 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
552 KB |
Output is correct |
12 |
Correct |
3 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
3 ms |
620 KB |
Output is correct |
21 |
Correct |
3 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
728 KB |
Output is correct |
25 |
Correct |
2 ms |
728 KB |
Output is correct |
26 |
Correct |
2 ms |
728 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
3 ms |
728 KB |
Output is correct |
30 |
Execution timed out |
2013 ms |
20256 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
20256 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
6 |
Correct |
1 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
2 ms |
552 KB |
Output is correct |
10 |
Correct |
2 ms |
552 KB |
Output is correct |
11 |
Correct |
3 ms |
552 KB |
Output is correct |
12 |
Correct |
3 ms |
572 KB |
Output is correct |
13 |
Correct |
2 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
572 KB |
Output is correct |
15 |
Correct |
2 ms |
572 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
3 ms |
620 KB |
Output is correct |
20 |
Correct |
3 ms |
620 KB |
Output is correct |
21 |
Correct |
3 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
728 KB |
Output is correct |
25 |
Correct |
2 ms |
728 KB |
Output is correct |
26 |
Correct |
2 ms |
728 KB |
Output is correct |
27 |
Correct |
2 ms |
728 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
3 ms |
728 KB |
Output is correct |
30 |
Execution timed out |
2013 ms |
20256 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |