Submission #1124546

#TimeUsernameProblemLanguageResultExecution timeMemory
1124546NotLinuxAncient Books (IOI17_books)C++20
0 / 100
1 ms328 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> p, int s) { int n = (int)p.size(); int ans[n-1]={0} , pre1[n-1]={0} , pre2[n-1]={0}; for(int i = 0;i<n;i++){ if(p[i] > i){ if(i+1 < n-1)pre1[i+1]++; if(p[i]+1 < n-1)pre1[p[i]+1]--; } else if(p[i] < i){ if(i-1 >= 0)pre2[i-1]++; if(p[i]-1 >= 0)pre2[p[i]-1]--; } } for(int i = 1;i<n-1;i++){ pre1[i] += pre1[i-1]; pre2[i] += pre2[i-1]; ans[i] = max(pre1[i] , pre2[i]) * 2; } bool bl = 0; for(int i = 0;i<s;i++){ if(ans[i]){ bl = 1; } else if(ans[i] == 0 and bl){ ans[i] = 2; } } bl = 0; for(int i = n-2;i>=s;i--){ if(ans[i]){ bl = 1; } else if(ans[i] == 0 and bl){ ans[i] = 2; } } long long ret = 0; for(int i = 0;i<n-1;i++)ret += ans[i]; return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...