Submission #744694

# Submission time Handle Problem Language Result Execution time Memory
744694 2023-05-19T02:15:24 Z emptypringlescan Passport (JOI23_passport) C++17
54 / 100
2000 ms 141932 KB
#include <bits/stdc++.h>
using namespace std;
int cnd;
vector<pair<int,int> > adj[800005];
struct node{
	int s,e,m;
	int nd;
	node *l,*r;
	node(int S, int E){
		s=S; e=E; m=(s+e)/2;
		nd=cnd;
		cnd++;
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			adj[l->nd].push_back({nd,0});
			adj[r->nd].push_back({nd,0});
		}
		else{
			adj[s].push_back({nd,0});
		}
	}
	void addedge(int S, int E, int N){
		if(S<=s&&e<=E){
			adj[nd].push_back({N,1});
			return;
		}
		if(E<=m) l->addedge(S,E,N);
		else if(S>m) r->addedge(S,E,N);
		else{
			l->addedge(S,m,N);
			r->addedge(m+1,E,N);
		}
	}
} *root;
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	cnd=n+1;
	root = new node(1,n);
	priority_queue<pair<int,pair<int,int> >,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;
	int dist[cnd][3];
	memset(dist,-1,sizeof(dist));
	for(int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		root->addedge(a,b,i+1);
		if(a==1) pq.push({1,{1,i+1}});
		if(b==n) pq.push({1,{2,i+1}});
	}
	while(!pq.empty()){
		int a=pq.top().first,b=pq.top().second.first,c=pq.top().second.second;
		pq.pop();
		if(dist[c][b]!=-1) continue;
		dist[c][b]=a;
		for(auto i:adj[c]){
			if(dist[i.first][b]==-1) pq.push({a+i.second,{b,i.first}});
		}
	}
	for(int i=1; i<=n; i++){
		//cout << dist[i][1] << ' ' << dist[i][2] << '\n';
		if(dist[i][1]!=-1&&dist[i][2]!=-1){
			pq.push({dist[i][1]+dist[i][2]-1,{0,i}});
		}
	}
	while(!pq.empty()){
		int a=pq.top().first,b=pq.top().second.first,c=pq.top().second.second;
		pq.pop();
		if(dist[c][b]!=-1) continue;
		dist[c][b]=a;
		for(auto i:adj[c]){
			if(dist[i.first][b]==-1) pq.push({a+i.second,{b,i.first}});
		}
	}
	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		int x;
		cin >> x;
		cout << dist[x][0] << '\n';
	}
}

# Verdict Execution time Memory Grader output
1 Correct 13 ms 19028 KB Output is correct
2 Correct 11 ms 19028 KB Output is correct
3 Correct 11 ms 19028 KB Output is correct
4 Correct 1874 ms 116976 KB Output is correct
5 Correct 547 ms 75724 KB Output is correct
6 Correct 278 ms 69892 KB Output is correct
7 Correct 393 ms 69964 KB Output is correct
8 Correct 236 ms 68560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19072 KB Output is correct
2 Correct 13 ms 19028 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 11 ms 19092 KB Output is correct
6 Correct 12 ms 19028 KB Output is correct
7 Correct 11 ms 19216 KB Output is correct
8 Correct 13 ms 19000 KB Output is correct
9 Correct 10 ms 19092 KB Output is correct
10 Correct 10 ms 19056 KB Output is correct
11 Correct 11 ms 19156 KB Output is correct
12 Correct 12 ms 19196 KB Output is correct
13 Correct 11 ms 19184 KB Output is correct
14 Correct 11 ms 19136 KB Output is correct
15 Correct 11 ms 19168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19072 KB Output is correct
2 Correct 13 ms 19028 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 11 ms 19092 KB Output is correct
6 Correct 12 ms 19028 KB Output is correct
7 Correct 11 ms 19216 KB Output is correct
8 Correct 13 ms 19000 KB Output is correct
9 Correct 10 ms 19092 KB Output is correct
10 Correct 10 ms 19056 KB Output is correct
11 Correct 11 ms 19156 KB Output is correct
12 Correct 12 ms 19196 KB Output is correct
13 Correct 11 ms 19184 KB Output is correct
14 Correct 11 ms 19136 KB Output is correct
15 Correct 11 ms 19168 KB Output is correct
16 Correct 18 ms 20052 KB Output is correct
17 Correct 15 ms 19784 KB Output is correct
18 Correct 16 ms 20052 KB Output is correct
19 Correct 19 ms 20048 KB Output is correct
20 Correct 16 ms 19668 KB Output is correct
21 Correct 13 ms 19796 KB Output is correct
22 Correct 16 ms 19748 KB Output is correct
23 Correct 17 ms 19972 KB Output is correct
24 Correct 15 ms 19924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19072 KB Output is correct
2 Correct 13 ms 19028 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 11 ms 19092 KB Output is correct
6 Correct 12 ms 19028 KB Output is correct
7 Correct 11 ms 19216 KB Output is correct
8 Correct 13 ms 19000 KB Output is correct
9 Correct 10 ms 19092 KB Output is correct
10 Correct 10 ms 19056 KB Output is correct
11 Correct 11 ms 19156 KB Output is correct
12 Correct 12 ms 19196 KB Output is correct
13 Correct 11 ms 19184 KB Output is correct
14 Correct 11 ms 19136 KB Output is correct
15 Correct 11 ms 19168 KB Output is correct
16 Correct 18 ms 20052 KB Output is correct
17 Correct 15 ms 19784 KB Output is correct
18 Correct 16 ms 20052 KB Output is correct
19 Correct 19 ms 20048 KB Output is correct
20 Correct 16 ms 19668 KB Output is correct
21 Correct 13 ms 19796 KB Output is correct
22 Correct 16 ms 19748 KB Output is correct
23 Correct 17 ms 19972 KB Output is correct
24 Correct 15 ms 19924 KB Output is correct
25 Correct 13 ms 19088 KB Output is correct
26 Correct 11 ms 19068 KB Output is correct
27 Correct 19 ms 20168 KB Output is correct
28 Correct 16 ms 19880 KB Output is correct
29 Correct 13 ms 19796 KB Output is correct
30 Correct 14 ms 19796 KB Output is correct
31 Correct 16 ms 19904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 19028 KB Output is correct
2 Correct 11 ms 19028 KB Output is correct
3 Correct 11 ms 19028 KB Output is correct
4 Correct 1874 ms 116976 KB Output is correct
5 Correct 547 ms 75724 KB Output is correct
6 Correct 278 ms 69892 KB Output is correct
7 Correct 393 ms 69964 KB Output is correct
8 Correct 236 ms 68560 KB Output is correct
9 Correct 11 ms 19072 KB Output is correct
10 Correct 13 ms 19028 KB Output is correct
11 Correct 10 ms 19028 KB Output is correct
12 Correct 10 ms 19028 KB Output is correct
13 Correct 11 ms 19092 KB Output is correct
14 Correct 12 ms 19028 KB Output is correct
15 Correct 11 ms 19216 KB Output is correct
16 Correct 13 ms 19000 KB Output is correct
17 Correct 10 ms 19092 KB Output is correct
18 Correct 10 ms 19056 KB Output is correct
19 Correct 11 ms 19156 KB Output is correct
20 Correct 12 ms 19196 KB Output is correct
21 Correct 11 ms 19184 KB Output is correct
22 Correct 11 ms 19136 KB Output is correct
23 Correct 11 ms 19168 KB Output is correct
24 Correct 18 ms 20052 KB Output is correct
25 Correct 15 ms 19784 KB Output is correct
26 Correct 16 ms 20052 KB Output is correct
27 Correct 19 ms 20048 KB Output is correct
28 Correct 16 ms 19668 KB Output is correct
29 Correct 13 ms 19796 KB Output is correct
30 Correct 16 ms 19748 KB Output is correct
31 Correct 17 ms 19972 KB Output is correct
32 Correct 15 ms 19924 KB Output is correct
33 Correct 13 ms 19088 KB Output is correct
34 Correct 11 ms 19068 KB Output is correct
35 Correct 19 ms 20168 KB Output is correct
36 Correct 16 ms 19880 KB Output is correct
37 Correct 13 ms 19796 KB Output is correct
38 Correct 14 ms 19796 KB Output is correct
39 Correct 16 ms 19904 KB Output is correct
40 Execution timed out 2048 ms 141932 KB Time limit exceeded
41 Halted 0 ms 0 KB -