# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869983 | Namviet2704 | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 1244 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int sqr = 205;
struct node
{
int v, p, w;
node(int v, int p, int w) : v(v), p(p), w(w) {}
};
int dis[30005];
bool vs[30005][210];
vector<int> adj[sqr];
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] << '\n';
}
Compilation message (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... |