제출 #151255

#제출 시각아이디문제언어결과실행 시간메모리
151255Bodo171고대 책들 (IOI17_books)C++14
100 / 100
360 ms26684 KiB
#include "books.h" #include <iostream> using namespace std; const int nmax=1000*1000+5; int st[nmax],dr[nmax],viz[nmax]; int n,to_l,to_r,l,r,i,x,l1,l2,r1,r2,oldl,oldr,steps_left,steps_right; long long abss(long long x) { if(x<0) return -x; return x; } void ext(int &L,int &R,int oldL,int oldR) { int nxtL,nxtR; while(oldL!=L||oldR!=R) { nxtL=L;nxtR=R; for(int it=oldL-1;it>=L;it--) { nxtL=min(nxtL,st[it]); nxtR=max(nxtR,dr[it]); } for(int it=oldR+1;it<=R;it++) { nxtL=min(nxtL,st[it]); nxtR=max(nxtR,dr[it]); } oldL=L;oldR=R; L=nxtL;R=nxtR; } } long long minimum_walk(vector<int> p, int s) { long long ans=0; n=p.size(); to_l=s;to_r=s; for(i=0; i<p.size(); i++) { if(p[i]!=i) { to_l=min(to_l,i); to_r=max(to_r,i); } ans+=1LL*abss(i-p[i]); if(!viz[i]) { st[i]=dr[i]=i; x=i; while(!viz[x]) { st[i]=min(st[i],x); dr[i]=max(dr[i],x); viz[x]=1; x=p[x]; } x=p[i]; while(x!=i) { st[x]=st[i]; dr[x]=dr[i]; x=p[x]; } } } l=st[s];r=dr[s]; ext(l,r,s,s); while(l>to_l||r<to_r) { l1=l,r1=r;oldl=l;oldr=r; steps_left=steps_right=0; while(l1>to_l&&r1==r) { l1--;steps_left+=2; ext(l1,r1,oldl,oldr); oldl=l1;oldr=r1; } l2=l,r2=r;oldl=l;oldr=r; while(r2<to_r&&l2==l) { r2++;steps_right+=2; ext(l2,r2,oldl,oldr); oldl=l2;oldr=r2; } if(r1>r) { ans+=1LL*min(steps_left,steps_right); l=l1;r=r1; } else { ans+=1LL*steps_left; ans+=1LL*steps_right; l=l1;r=r2; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

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