Submission #1072213

#TimeUsernameProblemLanguageResultExecution timeMemory
1072213DeathIsAweAncient Books (IOI17_books)C++17
22 / 100
69 ms21772 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; bool visited[1000005]; bool visitedgroup[1000005]; long long minimum_walk(vector<int> p, int s) { if (s != 0) {return 0;} int n = p.size(); while (n > 0) { if (p[n - 1] == n - 1) { n--; } else { break; } } if (n == 0) { return 0; } vector<int> right(n), dist(n), group(n); for (int i=0;i<n;i++) { visitedgroup[i] = false; visited[i] = false; dist[i] = 0; } if (n > 1000) { return 0; } int dummer, distcount, maxtrack, groupnum = 0; vector<int> temp; for (int i=0;i<n;i++) { if (visited[i]) {continue;} temp.clear(); dummer = p[i]; distcount = abs(i - p[i]); maxtrack = max(i, p[i]); temp.push_back(i); while (dummer != i) { distcount += abs(dummer - p[dummer]); maxtrack = max(maxtrack, p[dummer]); temp.push_back(dummer); dummer = p[dummer]; } for (int j: temp) { right[j] = maxtrack; dist[j] = distcount; group[j] = groupnum; } groupnum++; } //for (int i=0;i<n;i++) { // cout << right[i] << ' '; //} cout << '\n'; //for (int i=0;i<n;i++) { // cout << dist[i] << ' '; //} cout << '\n'; if (n > 1000) { return 0; } int ans = -2, dum = 0; while (dum < n) { dummer = dum; distcount = dist[dum]; visitedgroup[group[dum]] = true; dum = right[dum]; while (dummer < dum) { dummer++; if (visitedgroup[group[dummer]]) {continue;} distcount += dist[dummer]; visitedgroup[group[dummer]] = true; dum = max(dum, right[dummer]); } ans += 2 + distcount; dum++; } return ans; }
#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...