Submission #1028671

#TimeUsernameProblemLanguageResultExecution timeMemory
1028671parsadox2Ancient Books (IOI17_books)C++17
50 / 100
87 ms15956 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int a[N] , n; bool marked[N]; long long minimum_walk(vector<int> p, int s) { n = p.size(); long long ans = 0; int cnt = (p[0] == 0 ? 0 : 1); marked[p[0]] = true; for(int i = 1 ; i < n ; i++) { ans += max(2 * cnt , 2); if(p[i] > i) { cnt++; marked[p[i]] = true; } if(marked[i]) cnt--; } for(int i = n - 1 ; i > s ; i--) { if(p[i] != i) break; ans -= 2; } for(int i = 0 ; i < s ; i++) { if(p[i] != i) break; ans -= 2; } return ans; }
#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...