# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
153067 | songc | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 906 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M, S, E;
vector<int> V[30303];
int D[30303];
priority_queue<pii, vector<pii>, greater<pii>> PQ;
int main(){
scanf("%d %d", &N, &M);
for (int i=1; i<=M; i++){
int x, y;
scanf("%d %d", &x, &y);
if (i == 1) S = x;
if (i == 2) E = x;
V[x].push_back(y);
}
for (int i=0; i<N; i++) sort(V[i].begin(), V[i].end());
memset(D, -1, sizeof D);
PQ.push(pii(0, S));
while (!PQ.empty()){
int x, d;
tie(d,x) = PQ.top();
PQ.pop();
if (D[x] != -1) continue;
D[x] = d;
for (int v : V[x]){
for (int i=1; x-v*i>=0; i++){
PQ.push(pii(d+i, x-v*i));
auto it = lower_bound(V[x-v*i].begin(), V[x-v*i].end(), v);
if (it != V[x-v*i].end() && *it == v) break;
}
for (int i=1; x+v*i<N; i++){
PQ.push(pii(d+i, x+v*i));
auto it = lower_bound(V[x+v*i].begin(), V[x+v*i].end(), v);
if (it != V[x+v*i].end() && *it == v) break;
}
}
}
printf("%d\n", D[E]);
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... |