Submission #60479

#TimeUsernameProblemLanguageResultExecution timeMemory
60479Eae02Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1067 ms93804 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma pack(push, 1) struct QEntry { uint16_t building; uint16_t doge; int cost; }; #pragma pack(pop) std::bitset<30000> visited[30000]; 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]; dogesInBuildings[dogePositions[i]].push_back(i); } std::deque<QEntry> q; q.push_back(QEntry { dogePositions[0], 0, 0 }); visited[dogePositions[0]][0] = true; while (!q.empty()) { QEntry entry = q.front(); q.pop_front(); if (entry.doge == 1) { std::cout << entry.cost << std::endl; return 0; } for (int d : dogesInBuildings[entry.building]) { if (!visited[entry.building][d]) { visited[entry.building][d] = true; q.push_front(QEntry { entry.building, d, entry.cost }); break; } } int pBuilding = (int)entry.building - dogePowers[entry.doge]; if (pBuilding >= 0 && !visited[pBuilding][entry.doge]) { visited[pBuilding][entry.doge] = true; q.push_back(QEntry { pBuilding, entry.doge, entry.cost + 1 }); } int nBuilding = (int)entry.building + dogePowers[entry.doge]; if (nBuilding < numBuildings && !visited[nBuilding][entry.doge]) { visited[nBuilding][entry.doge] = true; q.push_back(QEntry { nBuilding, entry.doge, entry.cost + 1 }); } } std::cout << "-1" << std::endl; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:46: 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 });
                                              ^
skyscraper.cpp:55:57: warning: narrowing conversion of 'd' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
     q.push_front(QEntry { entry.building, d, entry.cost });
                                                         ^
skyscraper.cpp:64:63: 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 });
                                                               ^
skyscraper.cpp:71:63: 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 });
                                                               ^
#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...