Submission #355117

#TimeUsernameProblemLanguageResultExecution timeMemory
355117kylych03Ancient Books (IOI17_books)C++14
50 / 100
195 ms16088 KiB
#include "books.h" //#include "grader.cpp" #include <bits/stdc++.h> #define ll long long using namespace std; int vis[1000001]; long long minimum_walk(std::vector<int> p, int s) { ll ans=0; vector <pair<ll, ll>> vec; for(int i = 0 ; i < p.size(); i++){ ans+= abs( i - p[i]); int j = i; int l = i , r = i; while(vis[j]==0){ l=min(l,j); r = max(r,j); vis[j]=1; j = p[j]; } if(l!=r) vec.push_back(make_pair(l,r)); } vec.push_back(make_pair(s,s)); //cout << vec.size()<<endl; sort( vec.begin(), vec.end() ); for(int i = 1; i < vec.size();i++){ ans += (2 * max(0ll, vec[i].first - vec[i-1].second)); vec[i].second = max(vec[i].second, vec[i-1].second); } return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0 ; i < p.size(); i++){
      |                  ~~^~~~~~~~~~
books.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 1; i < vec.size();i++){
      |                 ~~^~~~~~~~~~~~
#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...