Submission #384786

#TimeUsernameProblemLanguageResultExecution timeMemory
384786kshitij_sodaniAncient Books (IOI17_books)C++14
0 / 100
17 ms23916 KiB
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' #include "books.h" llo ans=0; llo n; vector<llo> adj[1000001]; llo vis[1000001]; vector<llo> ss; void dfs(int no){ vis[no]=1; ss.pb(no); for(auto j:adj[no]){ if(vis[j]==0){ dfs(j); } } } long long minimum_walk(std::vector<int> p, int s) { while(p.size()){ if(p.back()==p.size()+1){ p.pop_back(); } else{ break; } } n=p.size(); if(n==0){ return 0; } for(int i=0;i<n;i++){ adj[i].pb(p[i]); } llo co=0; llo ans=0; for(int i=0;i<n;i++){ if(vis[i]==0){ ss.clear(); dfs(i); if(ss.size()==0){ continue; } co++; for(int j=0;j+1<ss.size();j++){ ans+=abs(ss[j]-ss[j+1]); } /* for(auto j:ss){ cout<<j<<",,"; } cout<<endl;*/ ans+=(abs(ss[0]-ss.back())); } } ans+=2*(co-1); return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:29:14: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if(p.back()==p.size()+1){
      |      ~~~~~~~~^~~~~~~~~~~~
books.cpp:55:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    for(int j=0;j+1<ss.size();j++){
      |                ~~~^~~~~~~~~~
#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...