# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
20887 | 14kg | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 153 ms | 33036 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
#include <queue>
#define N 30001
#define minus(x,y) (y?-(x):x)
#define Abs(x) (x>0?x:-(x))
#define LIMIT 1000
using namespace std;
typedef pair<int, pair<int, int> > pip;
int n, m, sw, ew, d[N];
bool check[N];
bool check2[N][LIMIT + 1];
vector<int> V[N];
queue<pip> Q;
int main() {
int x, y;
int w, p, c;
scanf("%d %d", &m, &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x, &y);
V[++x].push_back(y);
if (i == 1) sw = x;
if (i == 2) ew = x;
}
Q.push({ 0,{ sw,m + 1 } });
while (!Q.empty()) {
c = Q.front().first;
w = Q.front().second.first;
p = Q.front().second.second;
Q.pop();
if (check[ew]) break;
if (Abs(p) <= LIMIT) {
if(check2[w][Abs(p)]) continue;
check2[w][Abs(p)] = true;
}
if (1 <= w + p && w + p <= m) Q.push({ c + 1,{ w + p,p } });
if (!check[w]) {
check[w] = true, d[w] = c;
for (auto i : V[w]) {
if (1 <= w + i && w + i <= m) Q.push({ c + 1,{ w + i,i } });
if (1 <= w - i && w - i <= m) Q.push({ c + 1,{ w - i,-i } });
}
}
} printf("%d", check[ew] ? d[ew] : -1);
}
컴파일 시 표준 에러 (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... |