Submission #423052

#TimeUsernameProblemLanguageResultExecution timeMemory
423052MDarioAncient Books (IOI17_books)C++11
50 / 100
158 ms9156 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second long long minimum_walk(vector<int> p, int s){ ll n=p.size(), r=0, x=0, y=0, z=0; bool b[n]; for(int i=0; i<n; i++){ b[i]=0; if(p[i]==i)b[i]=1; } for(int i=0; i<n; i++){ if(!b[i]){ //cout << z << " "; if(i>z){ r+=2*(i-z); } r+=p[i]-i; y=p[i]; while(y!=i){ z=max(z, y); b[y]=1; r+=abs(p[y]-y); y=p[y]; } b[y]=1; z=max(z, y); } } return r; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:8:25: warning: unused variable 'x' [-Wunused-variable]
    8 |     ll n=p.size(), r=0, x=0, y=0, z=0;
      |                         ^
#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...