Submission #421133

#TimeUsernameProblemLanguageResultExecution timeMemory
421133schseAncient Books (IOI17_books)C++17
0 / 100
2 ms784 KiB
#include "books.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; struct unionfind { vector<int> root = vector<int>(1005); int find(int i) { if (root[i] == i) return i; return root[i] = find(root[i]); } bool unite(int a, int b) { a = find(a); b = find(b); if (a == b) return false; root[a] = b; return true; } } un; struct qnode { int dis, a, b; }; long long minimum_walk(std::vector<int> p, int s) { iota(un.root.begin(), un.root.end(), 0); vector<int> cycle(p.size(), -1); vector<vector<int>> cycles; long long triplenght = 0; for (int i = 0; i < p.size(); i++) { if (cycle[i] == -1 && p[i] != i) { int t = i; cycles.push_back({}); do { cycles[cycles.size() - 1].push_back(t); cycle[t] = cycles.size(); triplenght += abs(t - p[t]); t = p[t]; } while (t != i); } } vector<qnode> edges; for (int i = 0; i < cycles.size(); i++) { for (int e = 0; e < i; e++) { int mn = INT32_MAX; for (int a : cycles[i]) for (int b : cycles[e]) mn = min(mn, abs(a - b)); edges.push_back({mn, i, e}); } } sort(edges.begin(), edges.end(), [](qnode a, qnode b) { return a.dis < b.dis; }); for (qnode n : edges) { if (un.unite(n.a, n.b)) triplenght += 2 * n.dis; } int t = 0; while (cycles.size() && cycle[t++] == -1) triplenght += 2; return triplenght; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < p.size(); i++)
      |                  ~~^~~~~~~~~~
books.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for (int i = 0; i < cycles.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...