Submission #851540

# Submission time Handle Problem Language Result Execution time Memory
851540 2023-09-20T05:09:46 Z willychan Passport (JOI23_passport) C++14
0 / 100
2000 ms 972336 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds

const int N = 2e5+5;
vector<int> side[N];


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;cin>>n;		
	for(int i=1;i<=n;i++){
		int l,r;cin>>l>>r;	
		for(int j=l;j<=r;j++) side[j].push_back(i);
	}
	int dis1[n+1]={0};
	int disn[n+1]={0};
	dis1[1]=1;
	disn[n]=1;
	queue<int> q;
	q.push(1);
	while(q.size()){
		int a = q.front();
		q.pop();
		for(auto i : side[a]){
			if(dis1[i]) continue;
			dis1[i] = dis1[a]+1;
			q.push(i);
		}
	}
	queue<int> q2;
	q2.push(n);
	while(q2.size()){
		int a = q2.front();
		q2.pop();
		for(auto i : side[a]){
			if(disn[i]) continue;
			disn[i] = disn[a]+1;
			q2.push(i);
		}
	}
	int Q;cin>>Q;
	while(Q--){
		int x;cin>>x;
		if(dis1[x]==0 || disn[x]==0){
			cout<<-1<<"\n";
			continue;
		}
		cout<<max(dis1[x],disn[x])-1<<"\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Execution timed out 2127 ms 972336 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 5148 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Incorrect 1 ms 4956 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 5148 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Incorrect 1 ms 4956 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 5148 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Incorrect 1 ms 4956 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Execution timed out 2127 ms 972336 KB Time limit exceeded
5 Halted 0 ms 0 KB -