Submission #1029041

#TimeUsernameProblemLanguageResultExecution timeMemory
1029041amirhoseinfar1385Ancient Books (IOI17_books)C++17
0 / 100
0 ms348 KiB
#include"books.h" #include <vector> #include<bits/stdc++.h> const int maxn=1000000+10; using namespace std; int vis[maxn],visa[maxn]; int n; long long minimum_walk(std::vector<int> p, int s){ n=p.size(); long long mainres=0,last=0; int cnt1=0; for(int i=0;i<n;i++){ if(p[i]>i){ cnt1++; visa[p[i]]=1; } if(visa[i]){ cnt1--; } mainres+=cnt1*2; if(cnt1!=0){ last=i+1; } } for(int i=0;i<=last;i++){ if(vis[i]==0){ mainres+=2; int now=i; do{ vis[now]=1; now=p[now]; }while(now!=i); } } mainres-=2; return mainres; }
#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...