Submission #62626

#TimeUsernameProblemLanguageResultExecution timeMemory
62626TenuunAncient Books (IOI17_books)C++17
0 / 100
4 ms792 KiB
#include<bits/stdc++.h> using namespace std; bool vis[1000001]={false}; long long res=0, k; vector<int>v; void dfs(int u){ vis[u]=true; res+=abs(v[u]-u); if(v[u]==k) return; dfs(v[u]); } long long minimum_walk(std::vector<int> p, int s) { int last=0; v=p; for(int i=0; i<p.size(); i++){ if(i==p[i]) vis[i]=true; } for(int i=0; i<p.size(); i++){ if(vis[i]) continue; res+=i-last; k=i; dfs(i); last=i; } return res+last; }

Compilation message (stderr)

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