Submission #1062527

#TimeUsernameProblemLanguageResultExecution timeMemory
1062527Sir_Ahmed_ImranAncient Books (IOI17_books)C++17
12 / 100
1 ms600 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define append push_back #define add insert #define nl '\n' #define ff first #define ss second #define pii pair<int,int> #define pll pair<ll,ll> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define terminator main #define MAXN 1000000 int vis[MAXN]; ll minimum_walk(vector<int> v,int s){ ll o=0; int n,m,p,q; n=v.size(); for(int i=0;i<n;i++) vis[i]=0; for(int i=p=q=0;i<n;i++){ if(v[i]!=i && !vis[i] && q<i) p=i; m=i; while(!vis[m]){ o+=abs(v[m]-m); q=max(q,m); vis[m]=1; m=v[m]; } } return o+2*p; }
#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...