Submission #561026

#TimeUsernameProblemLanguageResultExecution timeMemory
561026nekiAncient Books (IOI17_books)C++14
50 / 100
208 ms48660 KiB
#include <bits/stdc++.h> #define ll long long #define vc vector #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; ll minimum_walk(vc<int> p, int s){ ll n=p.size(); ll ans=0; vc<ll> doseg(n);iota(all(doseg), 0); vc<ll> vis(n, 0); for(ll i=0;i<n;++i) if(!vis[i]){ vc<ll> cyc; for(ll cur=i;1;){ vis[cur]=1; cyc.push_back(cur); ll nex=p[cur]; ans+=abs(nex-cur); if(nex==i)break; cur=nex; } ll zac=(*min_element(all(cyc))), konc=(*max_element(all(cyc))); doseg[konc]=min(doseg[konc], zac); } vc<pair<ll, ll>> ints; for(ll i=0;i<n;++i){ while(ints.size() and doseg[i]<=ints.back().second) ints.pop_back(); if(ints.size()==0) ints.emplace_back((ll)0, i); else ints.emplace_back(ints.back().second+1, i); } ll st;for(ll i=0;i<ints.size();++i) if(ints[i].fi<=s and s<=ints[i].se) st=i; ll fl=st;for(ll i=st-1;i>=0;--i) if(ints[i].fi!=ints[i].se) fl=i; ll fr=st;for(ll i=st+1;i<ints.size();++i) if(ints[i].fi!=ints[i].se) fr=i; ans+=2 * (fr-fl); return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     ll st;for(ll i=0;i<ints.size();++i) if(ints[i].fi<=s and s<=ints[i].se) st=i;
      |                      ~^~~~~~~~~~~~
books.cpp:38:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     ll fr=st;for(ll i=st+1;i<ints.size();++i) if(ints[i].fi!=ints[i].se) fr=i;
      |                            ~^~~~~~~~~~~~
books.cpp:37:21: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     ll fl=st;for(ll i=st-1;i>=0;--i) if(ints[i].fi!=ints[i].se) fl=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...