# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
152168 | songc | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1084 ms | 73856 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> D[30303];
unordered_set<int> dchk[30303];
bool bchk[30303];
struct Data{
int x, y, d;
};
deque<Data> Q;
int main(){
scanf("%d %d", &N, &M);
int x, y;
scanf("%d %d", &x, &y);
D[x].push_back(y);
S = x;
scanf("%d %d", &x, &y);
D[x].push_back(y);
E = x;
for (int i=3; i<=M; i++){
scanf("%d %d", &x, &y);
D[x].push_back(y);
}
for (int v : D[S]){
if (dchk[S].find(v) == dchk[S].end()){
Q.push_back((Data){S, v, 0});
dchk[S].insert(v);
}
}
bchk[S] = true;
while (!Q.empty()){
Data T = Q.front();
Q.pop_front();
if (T.x == E){
printf("%d\n", T.d);
return 0;
}
if (!bchk[T.x]){
for (int v : D[T.x]){
if (dchk[T.x].find(v) == dchk[T.x].end()){
Q.push_front((Data){T.x, v, T.d});
dchk[T.x].insert(v);
}
}
bchk[T.x] = true;
}
if (T.x-T.y >= 0 && dchk[T.x-T.y].find(T.y) == dchk[T.x-T.y].end()){
Q.push_back((Data){T.x-T.y, T.y, T.d+1});
dchk[T.x-T.y].insert(T.y);
}
if (T.x+T.y < N && dchk[T.x+T.y].find(T.y) == dchk[T.x+T.y].end()){
Q.push_back((Data){T.x+T.y, T.y, T.d+1});
dchk[T.x+T.y].insert(T.y);
}
}
puts("-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... |