# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978544 | vjudge1 | Passport (JOI23_passport) | C++17 | 86 ms | 17056 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>
#define sz size()
#define ll long long
using namespace std;
const ll N = 3000;
const ll INF = N;
void solve()
{
ll n, Q, i, j, k;
cin >> n;
ll l[n + 1], r[n + 1];
for(i = 1; i <= n; ++i)
cin >> l[i] >> r[i];
cin >> Q;
while(Q--)
{
ll start;
cin >> start;
ll cl = start, cr = start;
vector<ll> d(n + 1, INF);
d[start] = 0;
multiset<pair<ll, ll>> q;
q.insert({0, start});
while(q.sz)
{
auto [x, s] = *q.begin();
q.erase(q.find({x, s}));
for(ll t = l[s]; t <= min(cl, s); ++t)
{
if(d[t] < x + 1) continue;
q.erase({d[t], t});
d[t] = x + 1;
q.insert({d[t], t});
}
cl = min(cl, l[s]);
for(ll t = max(s, cr); t <= r[s]; ++t)
{
if(d[t] < x + 1) continue;
q.erase({d[t], t});
d[t] = x + 1;
q.insert({d[t], t});
}
cr = max(cr, r[s]);
}
ll ans = max(d[1], d[n]);
cout << (ans < INF ? ans : -1) << '\n';
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
}
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... |