Submission #137290

#TimeUsernameProblemLanguageResultExecution timeMemory
137290choikiwonAncient Books (IOI17_books)C++17
Compilation error
0 ms0 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]; 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; if(A[i] == i) continue; int mx = -1e9; int u = i; while(!vis[u]) { vis[u] = 1; mx = max(mx, u); ret += abs(u - A[u]); u = A[u]; } V.push_back(pii(i, mx)); } if(V.size() == 0) return ret; int st = V[0].first; int ed = V[0].second; if(S < st) { ret += 2 * (st - S); } for(int i = 1; i < V.size(); i++) { if(ed < V[i].first) { ret += 2 * (V[i].first - ed); st = V[i].first; ed = V[i].second; continue; } ed = max(ed, V[i].second); } if(ed < S) { ret += 2 * (S - ed); } int mn = 1e9; for(int i = 0; i < N; i++) if(vis[i]) mn = min(mn, abs(i - S)); ret += 2 * mn; return ret; } int main() { int n, s; vector<int> p; cin >> n >> s; p.resize(n); for(int i = 0; i < n; i++) cin >> p[i]; cout << minimum_walk(p, s); }

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < V.size(); i++) {
                 ~~^~~~~~~~~~
/tmp/ccoTs4XJ.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccD1eeau.o:books.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status