# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
60497 | 2018-07-24T09:12:02 Z | Eae02 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 4 ms | 640 KB |
#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 && (i == 1 || dogePositions[i] - dogePowers[i] >= 0 || dogePositions[i] + dogePowers[i] < numBuildings)) dogesInBuildings[dogePositions[i]].push_back(i); } std::queue<QEntry> q; q.push(QEntry { dogePositions[0], 0, 0, true }); q.push(QEntry { dogePositions[0], 0, 0, false }); while (!q.empty()) { QEntry entry = q.front(); q.pop(); if (entry.doge() == 1 || dogePositions[1] == entry.building) { std::cout << entry.cost << std::endl; return 0; } if (!dogesInBuildings[entry.building].empty()) { int nextDoge = dogesInBuildings[entry.building].back(); dogesInBuildings[entry.building].pop_back(); int pBuilding = (int)entry.building - dogePowers[nextDoge]; if (pBuilding >= 0) q.push(QEntry { pBuilding, nextDoge, entry.cost + 1, true }); int nBuilding = (int)entry.building + dogePowers[nextDoge]; if (nBuilding < numBuildings) q.push(QEntry { nBuilding, nextDoge, entry.cost + 1, false }); } if (entry.left()) { int pBuilding = (int)entry.building - dogePowers[entry.doge()]; if (pBuilding >= 0) { q.push(QEntry { pBuilding, entry.doge(), entry.cost + 1, true }); } } else { int nBuilding = (int)entry.building + dogePowers[entry.doge()]; if (nBuilding < numBuildings) { q.push(QEntry { nBuilding, entry.doge(), entry.cost + 1, false }); } } } std::cout << "-1" << std::endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 564 KB | Output is correct |
4 | Correct | 3 ms | 564 KB | Output is correct |
5 | Correct | 3 ms | 564 KB | Output is correct |
6 | Correct | 3 ms | 564 KB | Output is correct |
7 | Correct | 2 ms | 596 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Output is correct |
2 | Correct | 3 ms | 596 KB | Output is correct |
3 | Correct | 3 ms | 596 KB | Output is correct |
4 | Correct | 2 ms | 596 KB | Output is correct |
5 | Correct | 2 ms | 596 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 4 ms | 628 KB | Output is correct |
8 | Correct | 3 ms | 628 KB | Output is correct |
9 | Correct | 3 ms | 628 KB | Output is correct |
10 | Correct | 4 ms | 628 KB | Output is correct |
11 | Incorrect | 3 ms | 628 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 628 KB | Output is correct |
2 | Correct | 3 ms | 628 KB | Output is correct |
3 | Correct | 3 ms | 628 KB | Output is correct |
4 | Correct | 3 ms | 628 KB | Output is correct |
5 | Correct | 2 ms | 628 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 4 ms | 628 KB | Output is correct |
8 | Correct | 3 ms | 628 KB | Output is correct |
9 | Correct | 3 ms | 628 KB | Output is correct |
10 | Correct | 3 ms | 628 KB | Output is correct |
11 | Incorrect | 4 ms | 628 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 628 KB | Output is correct |
2 | Correct | 2 ms | 628 KB | Output is correct |
3 | Correct | 3 ms | 628 KB | Output is correct |
4 | Correct | 2 ms | 628 KB | Output is correct |
5 | Correct | 2 ms | 628 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 3 ms | 628 KB | Output is correct |
8 | Correct | 2 ms | 628 KB | Output is correct |
9 | Correct | 2 ms | 628 KB | Output is correct |
10 | Correct | 3 ms | 636 KB | Output is correct |
11 | Incorrect | 3 ms | 636 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 636 KB | Output is correct |
2 | Correct | 3 ms | 636 KB | Output is correct |
3 | Correct | 3 ms | 636 KB | Output is correct |
4 | Correct | 3 ms | 636 KB | Output is correct |
5 | Correct | 3 ms | 636 KB | Output is correct |
6 | Correct | 3 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 636 KB | Output is correct |
8 | Correct | 3 ms | 636 KB | Output is correct |
9 | Correct | 3 ms | 636 KB | Output is correct |
10 | Correct | 2 ms | 636 KB | Output is correct |
11 | Incorrect | 4 ms | 640 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |