답안 #895654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895654 2023-12-30T13:04:56 Z Tuanlinh123 Passport (JOI23_passport) C++17
0 / 100
2000 ms 11340 KB
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

const ll maxn=200005, inf=1e9;
ll le[maxn], ri[maxn], L[maxn], R[maxn], dis[maxn];
priority_queue <pll, vector <pll>, greater<pll>> q;
vector <pll> A[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    for (ll i=1; i<=n; i++)
    {
        cin >> L[i] >> R[i];
        le[i]=ri[i]=dis[i]=inf;
    }
    for (ll i=1; i<=n; i++)
    {
        if (L[i]==1) le[i]=0;
        if (R[i]==n) ri[i]=0;
    }
    for (ll i=2; i<=n; i++)
        for (ll j=L[i]; j<i; j++)
            le[i]=min(le[i], le[j]+1);
    for (ll i=n-1; i>=1; i--)
        for (ll j=R[i]; j>i; j--)
            ri[i]=min(ri[i], ri[j]+1);
    for (ll i=1; i<=n; i++)
        A[n+1].pb({i, le[i]+ri[i]});
    for (ll i=1; i<=n; i++)
        for (ll j=L[i]; j<=R[i]; j++)
            A[j].pb({i, 1});
    dis[n+1]=0; q.push({0, n+1}); 
    while (!q.empty())
    {
        ll u=q.top().se, disu=q.top().fi; q.pop();
        if (disu!=dis[u])
            continue;
        for (pll child:A[u])
        {
            ll v=child.fi, w=child.se;
            if (dis[v]>disu+w)
            {
                dis[v]=disu+w;
                q.push({dis[v], v});
            }
        }
    }
    ll q; cin >> q;
    for (ll i=1; i<=q; i++)
    {
        ll x; cin >> x;
        if (dis[x]==inf) cout << "-1\n";
        else cout << dis[x]+1 << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Execution timed out 2037 ms 11340 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Incorrect 2 ms 8796 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Incorrect 2 ms 8796 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 1 ms 8792 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Incorrect 2 ms 8796 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 8796 KB Output is correct
4 Execution timed out 2037 ms 11340 KB Time limit exceeded
5 Halted 0 ms 0 KB -