답안 #1084380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084380 2024-09-06T07:01:08 Z Bananabread Passport (JOI23_passport) C++17
0 / 100
740 ms 1048576 KB
#include<bits/stdc++.h>
#define ll long long
#define ntr "\n"
#define mod (ll)(1e9+7)
#define taskname ""
#define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout);
using namespace std;
vector<ll> adj[3001];
ll dist[3001];
ll vis[3001];
ll n;
ll q;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //frep;
    cin>>n;
    for(int i=1;i<=n;i++){
        ll l,r;
        cin>>l>>r;
        for(int j=l;j<=r;j++){
            adj[i].push_back(j);
        }
    }
    cin>>q;
    for(int i=1;i<=q;i++){
        ll x;
        cin>>x;
        fill(dist+1,dist+n+1,1e18);
        fill(vis+1,vis+n+1,0);
        dist[x]=0;
        queue<ll> q;
        q.push(x);
        while(!q.empty()){
            ll u=q.front();
            q.pop();
            if(vis[u]) continue;
            vis[u]=1;
            for(auto v:adj[u]){
                if(dist[v]>dist[u]+1){
                    dist[v]=dist[u]+1;
                    q.push(v);
                }
            }
        }
        ll mx=max(dist[1],dist[n]);
        if(mx==1e18) cout<<-1;
        else cout<<mx;
        cout<<ntr;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 740 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 740 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -