Submission #835153

#TimeUsernameProblemLanguageResultExecution timeMemory
835153oscar1fAncient Books (IOI17_books)C++17
50 / 100
201 ms46300 KiB
#include<bits/stdc++.h> #include "books.h" using namespace std; using ll=long long; const ll MAX_TAILLE=1000*1000+5; ll nbVal,rep,posDeb,nbCompo,valFin,fin,maxFin; vector<ll> obj,listeCompo; ll idCompo[MAX_TAILLE],finCompo[MAX_TAILLE],tailleCompo[MAX_TAILLE]; void DFS(ll pos) { if (idCompo[pos]==0) { idCompo[pos]=nbCompo; finCompo[pos]=valFin; tailleCompo[nbCompo]++; DFS(obj[pos]); } } ll minimum_walk(vector<int> p, int s) { posDeb=s; nbVal=p.size(); for (auto i:p) { obj.push_back(i); } for (ll i=nbVal-1;i>=0;i--) { if (idCompo[i]==0) { nbCompo++; valFin=i; DFS(i); } rep+=abs(i-obj[i]); } fin=nbVal-1; while (fin>=0 and tailleCompo[idCompo[fin]]==1) { fin--; } //cout<<fin<<endl; int pos=0; while (pos<fin) { maxFin=max(maxFin,finCompo[pos]); if (maxFin==pos) { rep+=2; } pos++; } return rep; }
#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...