Submission #1291430

#TimeUsernameProblemLanguageResultExecution timeMemory
1291430nishuTeleporters (IOI08_teleporters)C++17
Compilation error
0 ms0 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; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:41:5: error: 'map' was not declared in this scope
   41 |     map<int, int> tele_map;
      |     ^~~
teleporters.cpp:5:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'?
    4 | #include <set>
  +++ |+#include <map>
    5 | using namespace std;
teleporters.cpp:41:9: error: expected primary-expression before 'int'
   41 |     map<int, int> tele_map;
      |         ^~~
teleporters.cpp:43:9: error: 'tele_map' was not declared in this scope
   43 |         tele_map[t.a] = t.b;
      |         ^~~~~~~~
teleporters.cpp:55:13: error: 'tele_map' was not declared in this scope
   55 |         if (tele_map.count(next)) {
      |             ^~~~~~~~