Submission #105246

#TimeUsernameProblemLanguageResultExecution timeMemory
105246puyu_liaoAncient Books (IOI17_books)C++14
50 / 100
257 ms8440 KiB
#include<bits/stdc++.h> #include<stdio.h> using namespace std; #define IOS {cin.tie(0);ios_base::sync_with_stdio(false);} #include"books.h" typedef long long lll; #define N 1000005 bitset<N> vis; lll minimum_walk(vector<int> p,int s){ vis.reset(); int ll = s,rr = s,gl,gr; lll ans = 0; for(int i=0;i<p.size();) if(!vis[i]){ gl = p.size()+1, gr = -1; int j = i; do{ int t = j; if(vis[t]) { j++; continue; } vis[t] = 1; while(!vis[p[t]]){ gl = min(gl,t); gr = max(gr,t); vis[p[t]] = 1; ans += abs(p[t] - t); t = p[t]; gl = min(gl,t); gr = max(gr,t); } ans += abs(p[t] - t); j++; }while(j<=gr); if(gl <= gr && gl < s) ll = min(ll,gl); if(gl <= gr && gr > s) rr = max(rr,gr); if(gl <= gr) ans -= 2*(gr - gl); i = j; } return ans + rr+rr-ll-ll; }

Compilation message (stderr)

books.cpp: In function 'lll minimum_walk(std::vector<int>, int)':
books.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();) if(!vis[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...