# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887320 | HossamHero7 | Passport (JOI23_passport) | C++14 | 0 ms | 348 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>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
int n;
cin>>n;
vector<pair<int,int>> v(n);
for(auto &[a,b] : v) cin>>a>>b , a -- , b--;
int q;
cin>>q;
while(q--){
int x;
cin>>x;
x --;
queue<pair<int,int>> q;
q.push({x,x});
vector<vector<int>> dep(n,vector<int>(n));
vector<vector<bool>> vis(n,vector<bool>(n));
vis[x][x] = 1;
while(q.size()){
auto [l,r] = q.front(); q.pop();
for(int i=l;i<=r;i++){
int L = min(l,v[i].first);
int R = max(r , v[i].second);
if(vis[L][R]) continue;
q.push({L,R});
vis[L][R] = 1;
dep[L][R] = dep[l][r] + 1;
}
}
cout<<dep[0][n-1]<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
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... |