답안 #970658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970658 2024-04-27T03:11:00 Z PenguinsAreCute Passport (JOI23_passport) C++17
100 / 100
932 ms 121164 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
//#define hello cout<<"line "<<__LINE__<<endl;
#define hello 69
using ii = pair<int,int>;
vector<ii> adj[400005];
void bfs(int s, int dist[]) {
	dist[s] = 0;
	priority_queue<ii,vector<ii>,greater<ii>> pq;
	for(pq.push({0,s});pq.size();) {
		auto [d,x] = pq.top(); pq.pop();
		if(d!=dist[x]) continue;
		for(auto [i,di]: adj[x]) if(dist[i]>d+di) {
			dist[i] = d+di;
			pq.push({d+di,i});
		}
	}
}
main() {
	int n; cin >> n;
	int l[n], r[n]; for(int i=0;i<n;i++) {cin>>l[i]>>r[i]; l[i]--;}
	for(int i=1;i<n;i++) {adj[i<<1].push_back({i,0}); adj[i<<1|1].push_back({i,0});}
	for(int i=0;i<n;i++) {
		for(int ll=l[i]+n,rr=r[i]+n;ll<rr;ll>>=1,rr>>=1) {
			if(ll&1) adj[ll++].push_back({i+n,1});
			if(rr&1) adj[--rr].push_back({i+n,1});
		}
	}
	int dista[2*n], distb[2*n], distt[2*n+5];
	fill(dista,dista+2*n,12102010);
	fill(distb,distb+2*n,12102010);
	fill(distt,distt+2*n+5,12102010);
	bfs(n,dista);
	bfs(2*n-1,distb);
	//for(int i=1;i<2*n;i++) printf("dista[%lld]=%lld\n",i,dista[i]);
	//for(int i=1;i<2*n;i++) printf("distb[%lld]=%lld\n",i,distb[i]);
	for(int i=0;i<n;i++) adj[2*n].push_back({i+n,max(dista[i+n],1LL)+max(distb[i+n],1LL)});
	bfs(2*n,distt);
	int q; cin >> q; for(int x;q--;) {
		cin >> x;
		cout << (distt[x+n-1]==12102010?-1:distt[x+n-1]-1) << "\n";
	}
}

Compilation message

passport.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9820 KB Output is correct
4 Correct 637 ms 105848 KB Output is correct
5 Correct 313 ms 65224 KB Output is correct
6 Correct 187 ms 54756 KB Output is correct
7 Correct 299 ms 94208 KB Output is correct
8 Correct 174 ms 84780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 2 ms 10072 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 2 ms 9828 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9832 KB Output is correct
13 Correct 3 ms 9972 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 2 ms 10072 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 2 ms 9828 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9832 KB Output is correct
13 Correct 3 ms 9972 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 6 ms 10612 KB Output is correct
17 Correct 6 ms 10332 KB Output is correct
18 Correct 6 ms 10844 KB Output is correct
19 Correct 7 ms 10864 KB Output is correct
20 Correct 5 ms 10332 KB Output is correct
21 Correct 5 ms 10332 KB Output is correct
22 Correct 4 ms 10588 KB Output is correct
23 Correct 5 ms 10840 KB Output is correct
24 Correct 4 ms 10600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 3 ms 9820 KB Output is correct
7 Correct 2 ms 10072 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 2 ms 9828 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9832 KB Output is correct
13 Correct 3 ms 9972 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 6 ms 10612 KB Output is correct
17 Correct 6 ms 10332 KB Output is correct
18 Correct 6 ms 10844 KB Output is correct
19 Correct 7 ms 10864 KB Output is correct
20 Correct 5 ms 10332 KB Output is correct
21 Correct 5 ms 10332 KB Output is correct
22 Correct 4 ms 10588 KB Output is correct
23 Correct 5 ms 10840 KB Output is correct
24 Correct 4 ms 10600 KB Output is correct
25 Correct 3 ms 9972 KB Output is correct
26 Correct 3 ms 9708 KB Output is correct
27 Correct 9 ms 10588 KB Output is correct
28 Correct 9 ms 10332 KB Output is correct
29 Correct 8 ms 10332 KB Output is correct
30 Correct 8 ms 10332 KB Output is correct
31 Correct 9 ms 10492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9820 KB Output is correct
4 Correct 637 ms 105848 KB Output is correct
5 Correct 313 ms 65224 KB Output is correct
6 Correct 187 ms 54756 KB Output is correct
7 Correct 299 ms 94208 KB Output is correct
8 Correct 174 ms 84780 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 2 ms 9820 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 2 ms 10072 KB Output is correct
16 Correct 2 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 2 ms 9828 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9832 KB Output is correct
21 Correct 3 ms 9972 KB Output is correct
22 Correct 3 ms 9820 KB Output is correct
23 Correct 3 ms 9820 KB Output is correct
24 Correct 6 ms 10612 KB Output is correct
25 Correct 6 ms 10332 KB Output is correct
26 Correct 6 ms 10844 KB Output is correct
27 Correct 7 ms 10864 KB Output is correct
28 Correct 5 ms 10332 KB Output is correct
29 Correct 5 ms 10332 KB Output is correct
30 Correct 4 ms 10588 KB Output is correct
31 Correct 5 ms 10840 KB Output is correct
32 Correct 4 ms 10600 KB Output is correct
33 Correct 3 ms 9972 KB Output is correct
34 Correct 3 ms 9708 KB Output is correct
35 Correct 9 ms 10588 KB Output is correct
36 Correct 9 ms 10332 KB Output is correct
37 Correct 8 ms 10332 KB Output is correct
38 Correct 8 ms 10332 KB Output is correct
39 Correct 9 ms 10492 KB Output is correct
40 Correct 932 ms 106620 KB Output is correct
41 Correct 590 ms 65224 KB Output is correct
42 Correct 715 ms 120608 KB Output is correct
43 Correct 686 ms 121164 KB Output is correct
44 Correct 464 ms 56132 KB Output is correct
45 Correct 509 ms 65076 KB Output is correct
46 Correct 228 ms 34080 KB Output is correct
47 Correct 687 ms 88456 KB Output is correct
48 Correct 556 ms 86216 KB Output is correct