# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
870359 | Namviet2704 | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 122 ms | 8992 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int sqr = 205;
const int N = 4e4 + 2;
struct node
{
int v, p, w;
node(int v, int p, int w) : v(v), p(p), w(w) {}
};
int dis[N];
bool vs[N][sqr + 10];
vector<int> adj[N];
queue<node> q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int s, t, n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int v, p;
cin >> v >> p;
adj[v].push_back(p);
if (i == 0)
s = v;
if (i == 1)
t = v;
}
memset(dis, -1, sizeof(dis));
q.emplace(s, 0, 0);
while (!q.empty())
{
node h = q.front();
q.pop();
if (h.v < 0 || h.v >= n)
continue;
if (abs(h.p) < sqr)
{ // neu p < can thi chi duyet qua 1 lan
if (vs[h.v][abs(h.p)])
continue;
vs[h.v][abs(h.p)] = 1;
}
if (dis[h.v] == -1)
{
dis[h.v] = h.w;
for (int p : adj[h.v])
{
q.emplace(h.v + p, p, h.w + 1); // di theo buoc nhay p ve huong ben phai
q.emplace(h.v - p, -p, h.w + 1); // di theo buoc nhay p ve huong ben trai
}
}
q.emplace(h.v + h.p, h.p, h.w + 1); // tiep tuc di theo buoc nhay
}
cout << dis[t];
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... |