Submission #593991

#TimeUsernameProblemLanguageResultExecution timeMemory
593991AlperenTAncient Books (IOI17_books)C++17
50 / 100
142 ms22744 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long minimum_walk(vector<int> p, int s){ long long ans = 0, mx = -1, n = p.size(); vector<long long> arr(n + 1, 0); for(int i = 0; i < n; i++){ arr[min(i, p[i])]++; arr[max(i, p[i])]--; } for(int i = 1; i < n; i++) arr[i] += arr[i - 1]; for(int i = 0; i < n; i++) if(arr[i]) mx = i; return (mx == -1 ? 0ll : accumulate(arr.begin(), arr.begin() + mx + 1, 0ll) + count(arr.begin(), arr.begin() + mx + 1, 0) * 2); }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:7:15: warning: unused variable 'ans' [-Wunused-variable]
    7 |     long long ans = 0, mx = -1, n = p.size();
      |               ^~~
#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...