Submission #60489

#TimeUsernameProblemLanguageResultExecution timeMemory
60489Eae02Jakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
1057 ms2668 KiB
#include <bits/stdc++.h> #pragma pack(push, 1) struct QEntry { uint16_t building; uint16_t dogeAndL; int cost; QEntry(uint16_t building, uint16_t doge, int cost, bool left) { this->building = building; this->cost = cost; this->dogeAndL = (doge << 1) | (left ? 1 : 0); } bool left() { return dogeAndL & 0x1; } uint16_t doge() { return dogeAndL >> 1; } }; #pragma pack(pop) int main() { int numBuildings, numDoges; std::cin >> numBuildings; std::cin >> numDoges; std::vector<std::vector<int>> dogesInBuildings(numBuildings); std::vector<int> dogePositions(numDoges); std::vector<int> dogePowers(numDoges); for (int i = 0; i < numDoges; i++) { std::cin >> dogePositions[i]; std::cin >> dogePowers[i]; if (i != 0) dogesInBuildings[dogePositions[i]].push_back(i); } std::deque<QEntry> q; q.push_back(QEntry { dogePositions[0], 0, 0, true }); q.push_back(QEntry { dogePositions[0], 0, 0, false }); while (!q.empty()) { QEntry entry = q.front(); q.pop_front(); if (entry.doge() == 1 || dogePositions[1] == entry.building) { std::cout << entry.cost << std::endl; return 0; } for (int nextDoge : dogesInBuildings[entry.building]) { dogesInBuildings[entry.building].pop_back(); q.push_front(QEntry { entry.building, nextDoge, entry.cost, true }); q.push_front(QEntry { entry.building, nextDoge, entry.cost, false }); } dogesInBuildings[entry.building].clear(); /* if (!dogesInBuildings[entry.building].empty()) { int nextDoge = dogesInBuildings[entry.building].back(); dogesInBuildings[entry.building].pop_back(); q.push_front(QEntry { entry.building, nextDoge, entry.cost, true }); q.push_front(QEntry { entry.building, nextDoge, entry.cost, false }); } */ if (entry.left()) { int pBuilding = (int)entry.building - dogePowers[entry.doge()]; if (pBuilding >= 0) { q.push_back(QEntry { pBuilding, entry.doge(), entry.cost + 1, true }); } } else { int nBuilding = (int)entry.building + dogePowers[entry.doge()]; if (nBuilding < numBuildings) { q.push_back(QEntry { nBuilding, entry.doge(), entry.cost + 1, false }); } } } std::cout << "-1" << std::endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:52: warning: narrowing conversion of 'dogePositions.std::vector<int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
  q.push_back(QEntry { dogePositions[0], 0, 0, true });
                                                    ^
skyscraper.cpp:51:53: warning: narrowing conversion of 'dogePositions.std::vector<int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
  q.push_back(QEntry { dogePositions[0], 0, 0, false });
                                                     ^
skyscraper.cpp:67:69: warning: narrowing conversion of 'nextDoge' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_front(QEntry { entry.building, nextDoge, entry.cost, true });
                                                                     ^
skyscraper.cpp:68:70: warning: narrowing conversion of 'nextDoge' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_front(QEntry { entry.building, nextDoge, entry.cost, false });
                                                                      ^
skyscraper.cpp:86:72: warning: narrowing conversion of 'pBuilding' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
     q.push_back(QEntry { pBuilding, entry.doge(), entry.cost + 1, true });
                                                                        ^
skyscraper.cpp:94:73: warning: narrowing conversion of 'nBuilding' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
     q.push_back(QEntry { nBuilding, entry.doge(), entry.cost + 1, false });
                                                                         ^
#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...