Submission #1058681

#TimeUsernameProblemLanguageResultExecution timeMemory
1058681shenfe1Ancient Books (IOI17_books)C++17
0 / 100
4 ms26588 KiB
#include <bits/stdc++.h> #include "books.h" #pragma GCC optimize("Ofast") using namespace std; #define pb push_back #define pii pair<int,int> #define sz(s) (int)s.size() #define F first #define S second #define all(v) v.begin(),v.end() #define ll long long const int MAX=1e6+10; int n; vector<int> g[MAX]; bool use[MAX]; vector<int> vec; int pref[MAX]; ll minimum_walk(vector<int> p,int s){ n=sz(p); ll ans=0; for(int i=0;i<n;i++){ ans+=abs(i-p[i]); } vector<vector<int>> x; vector<pii> seg; for(int i=0;i<n;i++){ if(!use[i]){ vec.clear(); int v=i; while(!use[v]){ vec.pb(v); use[v]=1; v=p[v]; } sort(all(vec)); seg.pb({vec[0],vec.back()}); x.pb(vec); } } int L,R; for(vector<int> v:x){ for(int f:v){ if(f==s){ L=v[0],R=v.back(); } } } while(R-L+1!=n){ // cout<<L<<" "<<R<<"\n"; bool ok=0; for(int i=0;i<sz(seg);i++){ auto [l,r]=seg[i]; for(int pos:x[i]){ if(L<=pos&&pos<=R){ if(l<L||r>R)ok=1; L=min(L,l); R=max(R,r); } } } if(!ok){ if(L-1>=0){ L--; ans+=2; } if(R+1<n){ R++; ans+=2; } } } return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:54:12: warning: 'R' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     while(R-L+1!=n){
      |           ~^~
books.cpp:54:12: warning: 'L' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...