# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
453279 | nonsensenonsense1 | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 465 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <deque>
struct node {
int pos, dist;
node *left, *right;
bool vis;
node(int pos_ = -1) {
pos = pos_;
left = right = 0;
vis = false;
dist = ~(1 << 31);
}
};
const int N = 30000;
const int K = 180;
int n, m;
node g[K][N];
std::vector<node *> top[N];
std::deque<node *> dq;
void go(node *cur, node *to, bool w)
{
if (to->dist > cur->dist + w) {
to->dist = cur->dist;
if (w) {
++to->dist;
dq.push_back(to);
}
else dq.push_front(to);
}
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < K; ++i) {
for (int j = 0; j < N; ++j) {
g[i][j].pos = j;
if (i) {
if (j >= i) g[i][j].left = g[i] + j - i;
if (j + i < N) g[i][j].right = g[i] + j + i;
}
}
}
int s, t;
for (int i = 0; i < m; ++i) {
int b, p;
scanf("%d%d", &b, &p);
if (!i) s = b;
if (i == 1) t = b;
if (p < K) top[b].push_back(g[p] + b);
else {
node *r = new node(b);
top[b].push_back(r);
node *prev = r;
for (int j = b - p; j >= 0; j -= p) {
node *cur = new node(j);
cur->right = prev;
prev->left = cur;
prev = cur;
}
prev = r;
for (int j = b + p; j < N; j += p) {
node *cur = new node(j);
cur->left = prev;
prev->right = cur;
prev = cur;
}
}
}
g[0][s].dist = 0;
dq.push_back(g[0] + s);
while (!dq.empty()) {
node *cur = dq.front();
dq.pop_front();
if (!cur->vis) {
cur->vis = true;
if (cur >= g[0] && cur < g[1]) for (int i = 0; i < (int)top[cur->pos].size(); ++i) go(cur, top[cur->pos][i], 0);
else {
go(cur, g[0] + cur->pos, 0);
if (cur->left) go(cur, cur->left, 1);
if (cur->right) go(cur, cur->right, 1);
}
}
}
if (g[0][t].dist == ~(1 << 31)) printf("-1\n");
else printf("%d\n", g[0][t].dist);
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... |