Submission #136734

#TimeUsernameProblemLanguageResultExecution timeMemory
136734StevenHAncient Books (IOI17_books)C++14
12 / 100
3 ms376 KiB
#include "books.h" #include <cstdio> using namespace std; const int maxn=1000005; bool vis[maxn]; bool loop[maxn]; long long aabs(int x) { long long xx = (long long)(x); if(x<0)return -1*x; else return x; } long long minimum_walk(std::vector<int> p, int s) { long long ans=0; for(int i=0;i<p.size();i++) { if(vis[i]==0) { int k=i; do { vis[k]=1; //break; //printf("%d %d\n",k,p[k]); ans+=aabs(p[k]-k); k=p[k]; }while(k!=i); } } for(int i=0;i<p.size();i++) { if(i==p[i]) loop[i]=1; else loop[i]=0; } int k=0; while(loop[k]==1)k++; if(k==p.size())return 0; ans+=k*2; return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int aabs(int)':
books.cpp:9:12: warning: unused variable 'xx' [-Wunused-variable]
  long long xx = (long long)(x);
            ^~
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:17:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();i++)
              ~^~~~~~~~~
books.cpp:32:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size();i++)
              ~^~~~~~~~~
books.cpp:41:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(k==p.size())return 0;
     ~^~~~~~~~~~
#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...