# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1024856 | 2024-07-16T11:15:28 Z | Svizel_pritula | Longest Trip (IOI23_longesttrip) | C++17 | 7 ms | 428 KB |
#include <bits/stdc++.h> #include "longesttrip.h" int find_opposite(std::vector<int> set, int node) { for (auto p = set.begin(); p < set.end(); p++) { if (are_connected({node}, {*p})) { return *p; } } } std::vector<int> longest_trip(int cities, int density) { std::vector<int> path; path.push_back(0); std::vector<int> unconnected; for (int i = 1; i < cities; i++) unconnected.push_back(i); while (unconnected.size() > 0) { bool found = false; for (auto p = unconnected.begin(); p < unconnected.end(); p++) { if (are_connected({path.back()}, {*p})) { path.push_back(*p); unconnected.erase(p); found = true; break; } } if (!found) { break; } } if (unconnected.size() == 0) return path; int last_join_point = -1; int best_distance = std::numeric_limits<int>::max(); int best_start = 0; int best_end = path.size() - 1; for (int i = 0; i <= path.size(); i++) { if (are_connected(unconnected, {path[i]})) { int distance = i - last_join_point - 1; if (distance < best_distance) { best_distance = distance; best_start = last_join_point; best_end = i; } last_join_point = i; } } int distance = path.size() - last_join_point - 1; if (distance < best_distance) { best_distance = distance; best_start = last_join_point; best_end = path.size(); } int start_op = best_start == -1 ? unconnected.front() : find_opposite(unconnected, path[best_start]); int end_op = best_end == path.size() ? unconnected.back() : find_opposite(unconnected, path[best_end]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 344 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 6 ms | 344 KB | Output is correct |
3 | Correct | 5 ms | 344 KB | Output is correct |
4 | Correct | 5 ms | 424 KB | Output is correct |
5 | Correct | 5 ms | 428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 5 ms | 344 KB | Output is correct |
3 | Correct | 4 ms | 344 KB | Output is correct |
4 | Correct | 5 ms | 344 KB | Output is correct |
5 | Correct | 7 ms | 344 KB | Output is correct |
6 | Runtime error | 0 ms | 344 KB | Execution killed with signal 6 |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 344 KB | Output is correct |
2 | Correct | 5 ms | 344 KB | Output is correct |
3 | Correct | 5 ms | 344 KB | Output is correct |
4 | Correct | 7 ms | 344 KB | Output is correct |
5 | Correct | 7 ms | 344 KB | Output is correct |
6 | Runtime error | 1 ms | 344 KB | Execution killed with signal 6 |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 5 ms | 356 KB | Output is correct |
3 | Correct | 5 ms | 344 KB | Output is correct |
4 | Correct | 7 ms | 344 KB | Output is correct |
5 | Correct | 5 ms | 344 KB | Output is correct |
6 | Runtime error | 0 ms | 340 KB | Execution killed with signal 6 |
7 | Halted | 0 ms | 0 KB | - |