# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60475 | Eae02 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1080 ms | 12620 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.
#include <bits/stdc++.h>
#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 });
}
}
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)
# | 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... |