Submission #137275

#TimeUsernameProblemLanguageResultExecution timeMemory
137275choikiwonAncient Books (IOI17_books)C++17
0 / 100
2 ms380 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1000010; int N, S; int A[maxn], vis[maxn], Mx[maxn]; vector<pii> V; ll minimum_walk(std::vector<int> p, int s) { N = p.size(); S = s; for(int i = 0; i < N; i++) { A[i] = p[i]; } ll ret = 0; for(int i = 0; i < N; i++) { if(vis[i]) continue; int mx = -1e9; int mn = 1e9; int cnt = 0; int u = i; while(!vis[u]) { vis[u] = 1; cnt++; if(u <= S) { mx = max(mx, u); } if(u >= S) { mn = min(mn, u); } ret += abs(u - A[u]); u = A[u]; } if(cnt >= 2) V.push_back(pii(S - mx, mn - S)); } V.push_back(pii(0, 0)); sort(V.begin(), V.end()); for(int i = (int)V.size() - 1; i >= 0; i--) { Mx[i] = V[i].second; Mx[i] = max(Mx[i], Mx[i + 1]); } int Mn = 1e9; for(int i = 0; i < V.size(); i++) { Mn = min(Mn, V[i].first + Mx[i + 1]); } ret += 2 * Mn; return ret; }

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < V.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...