# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
66658 | tincamatei | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 201 ms | 112820 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 30000;
bitset<MAX_N> doges[MAX_N];
vector<int> scrapers[MAX_N];
int dist[MAX_N];
int doggoB[MAX_N], doggoP[MAX_N];
int dijkstra(int n, int src, int dest) {
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
memset(dist, 0x3f3f3f3f, sizeof(dist));
dist[src] = 0;
pq.push(make_pair(0, src));
while(!pq.empty()) {
int nod = pq.top().second, distNod = pq.top().first;
pq.pop();
if(distNod == dist[nod]) {
if(nod == dest)
return distNod;
for(auto dog: scrapers[nod]) {
int it = nod - dog, cost = 1;
while(it >= 0) {
if(dist[nod] + cost < dist[it]) {
dist[it] = dist[nod] + cost;
pq.push(make_pair(dist[it], it));
}
if(doges[it][dog])
break;
it -= dog;
++cost;
}
it = nod + dog, cost = 1;
while(it < n) {
if(dist[nod] + cost < dist[it]) {
dist[it] = dist[nod] + cost;
pq.push(make_pair(dist[it], it));
}
if(doges[it][dog])
break;
it += dog;
++cost;
}
}
}
}
return -1;
}
int main() {
int n, m, b, p;
scanf("%d%d", &n, &m);
for(int i = 0; i < m; ++i) {
scanf("%d%d", &b, &p);
doggoB[i] = b;
doggoP[i] = p;
if(!doges[b][p]) {
scrapers[b].push_back(p);
doges[b][p] = true;
}
}
printf("%d", dijkstra(n, doggoB[0], doggoB[1]));
return 0;
}
컴파일 시 표준 에러 (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... |