# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
648637 | alvinpiter | Teleporters (IOI08_teleporters) | C++17 | 1087 ms | 42012 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Model the system as a graph, where each node (except the first and the last) is an interval between two consecutive
teleport endpoints.
Observation:
The graph will consist of exactly 1 line graph and some (maybe 0) cycles.
The line graph is the the intervals that we will pass through, while the cycles are the intervals we won't pass through.
Observation:
The answer to the problem is K - 1, where K is the number of nodes in the final line graph. So our goal is to maximize
this value.
Observation:
Adding a teleport means that we will interfere at most 2 intervals, i.e nodes. There are 3 possible actions:
1. Add a teleport on an interval. This action adds 1 node to the affected subgraph, and also add 1 cycle with length 1.
2. Add a teleport that connects two different intervals:
a. The intervals are in the same subgraph -> This is not beneficial.
b. The intervals are in different subgraphs -> These subgraphs are merged into a larger subgraph, it has 2 more nodes.
Picture the teleport "hooks" both subgraph.
Algorithm:
* Build the graph
* Identify the line graph and the cycles
* Connect the line graph to the longest cycles first, using action 2b above. Do this as many times as possible.
* If there is still teleports left to be built, alternate action 1 and 2b.
*/
#include<bits/stdc++.h>
using namespace std;
#define INF 2000000002
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |