| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1291430 | nishu | Teleporters (IOI08_teleporters) | C++17 | 0 ms | 0 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
struct Teleporter {
int a, b;
};
int main() {
int N, M;
cin >> N >> M;
vector<Teleporter> teleporters(N);
set<int> endpoints;
for (int i = 0; i < N; ++i) {
cin >> teleporters[i].a >> teleporters[i].b;
endpoints.insert(teleporters[i].a);
endpoints.insert(teleporters[i].b);
}
// Add new teleporters (simple version: just place them at unused unique positions)
int current = 1;
while (M > 0) {
while (endpoints.count(current)) ++current;
int a = current++;
while (endpoints.count(current)) ++current;
int b = current++;
teleporters.push_back({a, b});
endpoints.insert(a);
endpoints.insert(b);
--M;
}
// Simulate journey from 0 eastward: sort endpoints
vector<int> events(endpoints.begin(), endpoints.end());
sort(events.begin(), events.end());
// Map each endpoint to its pair
map<int, int> tele_map;
for (auto &t : teleporters) {
tele_map[t.a] = t.b;
tele_map[t.b] = t.a;
}
int position = 0;
int points = 0;
while (position < events.back()) {
auto it = upper_bound(events.begin(), events.end(), position);
if (it == events.end()) break;
int next = *it;
// If next is a teleporter endpoint, use it
if (tele_map.count(next)) {
position = tele_map[next];
points++;
} else {
position = next;
}
}
cout << "Total points: " << points << endl;
return 0;
}
