Submission #997536

# Submission time Handle Problem Language Result Execution time Memory
997536 2024-06-12T13:13:48 Z Abito Passport (JOI23_passport) C++17
0 / 100
224 ms 103384 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2505;
int dis[N][N],L[N],R[N],n,q;
pair<int,int> par[N][N];
void bfs(int s){
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) dis[i][j]=INT_MAX;
    dis[L[s]][R[s]]=1;par[L[s]][R[s]]={s,s};
    queue<pair<int,int>> q;
    q.push({L[s],R[s]});
    while (!q.empty()){
        int l=q.front().F,r=q.front().S;
        q.pop();
        for (int i=l;i<par[l][r].F;i++){
            int l1=min(l,L[i]),r1=max(r,R[i]);
            if (dis[l1][r1]!=INT_MAX) continue;
            dis[l1][r1]=dis[l][r]+1;
            par[l1][r1]={l,r};
            q.push({l1,r1});
        }
        for (int i=r;i>par[l][r].S;i--){
            int l1=min(l,L[i]),r1=max(r,R[i]);
            if (dis[l1][r1]!=INT_MAX) continue;
            dis[l1][r1]=dis[l][r]+1;
            par[l1][r1]={l,r};
            q.push({l1,r1});
        }

    }return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>L[i]>>R[i];
    cin>>q;
    while (q--){
        int x;cin>>x;
        bfs(x);
        if (dis[1][n]==INT_MAX) cout<<-1<<endl;
        else cout<<dis[1][n]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Runtime error 224 ms 103384 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Incorrect 1 ms 12768 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Incorrect 1 ms 12768 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Incorrect 1 ms 12768 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Runtime error 224 ms 103384 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -