| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1250264 | hainam2k9 | Passport (JOI23_passport) | C++20 | 2096 ms | 34708 KiB | 
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,q,rs[3005],dist[3005],dist1[3005],distn[3005];
vector<int> adj[3005],adjrev[3005];
void bfs(int u, int dist[]){
    fill(dist+1,dist+n+1,1e9);
    queue<int> q;
    dist[u]=0, q.ins(u);
    while(!q.empty()){
        u=q.front(), q.pop();
        for(int& v : adjrev[u])
            if(dist[v]>dist[u]+1) dist[v]=dist[u]+1, q.ins(v);
    }
}
int bfs2(int u){
    int MIN=1e9;
    fill(dist+1,dist+n+1,1e9);
    queue<int> q;
    dist[u]=0, q.ins(u);
    while(!q.empty()){
        u=q.front(), q.pop();
        MIN=min(MIN,dist[u]+dist1[u]+distn[u]-(u!=1&&u!=n));
        for(int& v : adj[u])
            if(dist[v]>dist[u]+1) dist[v]=dist[u]+1, q.ins(v);
    }
    if(MIN>=1e9) return -1;
    return MIN;
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n;
    for(int i = 1; i<=n; ++i){
        int l,r;
        cin >> l >> r;
        for(int j = l; j<=r; ++j)
            if(j!=i) adj[i].pb(j), adjrev[j].pb(i);
    }
    bfs(1,dist1);
    bfs(n,distn);
    for(int i = 1; i<=n; ++i)
        rs[i]=bfs2(i);
    cin >> q;
    while(q--){
        int x;
        cin >> x;
        cout << rs[x] << "\n";
    }
}
컴파일 시 표준 에러 (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... | ||||
