Submission #1113012

#TimeUsernameProblemLanguageResultExecution timeMemory
1113012SalihSahinAncient Books (IOI17_books)C++14
12 / 100
1 ms504 KiB
#include <bits/stdc++.h> #define pb push_back #include "books.h" using namespace std; long long minimum_walk(vector<int> p, int s) { long long ans = 0; int n = p.size(); int mxs = 0; vector<int> vis(n); vector<array<int, 2> > cyc; for(int i = 0; i < n; i++){ if(vis[i] || p[i] == i) continue; int l = i, r = i; int x = i; long long add = 0; while(!vis[x]){ vis[x] = 1; add += abs(x - p[x]); x = p[x]; r = max(r, x); } cyc.pb({l, r}); ans += add; } int rval = 0; for(int i = 0; i < cyc.size(); i++){ if(cyc[i][0] > rval) mxs = max(mxs, cyc[i][0]); rval = cyc[i][1]; } ans += mxs*2; return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int i = 0; i < cyc.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...