Submission #1069618

# Submission time Handle Problem Language Result Execution time Memory
1069618 2024-08-22T07:14:49 Z 김은성(#11131) Passport (JOI23_passport) C++17
40 / 100
2000 ms 88452 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll KEY = 1.557e8;
const int INF = 1.557e8;
unordered_map<ll, int> memo;
int lb[200009], rb[200009];
int n, minl[1<<19], maxr[1<<19];
void settree(int v, int l, int r){
	if(l==r){
		minl[v] = lb[l];
		maxr[v] = rb[l];
	}
	else{
		int mid = (l+r)/2;
		settree(2*v, l, mid);
		settree(2*v+1, mid+1, r);
		minl[v] = min(minl[2*v], minl[2*v+1]);
		maxr[v] = max(maxr[2*v], maxr[2*v+1]);
	}
}
int minquery(int v, int l, int r, int s, int e){
	if(e<l || r<s)
		return INF;
	if(s<=l && r<=e)
		return minl[v];
	int mid = (l+r)/2;
	return min(minquery(2*v, l, mid, s, e), minquery(2*v+1, mid+1, r, s, e));
}
int maxquery(int v, int l, int r, int s, int e){
	if(e<l || r<s)
		return -1;
	if(s<=l && r<=e)
		return maxr[v];
	int mid = (l+r)/2;
	return max(maxquery(2*v, l, mid, s, e), maxquery(2*v+1, mid+1, r, s, e));
}
int solve(int l, int r){
	if(l==1 && r==n)
		return 0;
	auto it = memo.find(l * KEY + r);
	if(it != memo.end())
		return it->second;
	int pl = minquery(1, 1, n, l, r), pr = maxquery(1, 1, n, l, r);
	//printf("l=%d r=%d pl=%d pr=%d\n",l, r, pl,pr);
	int ret = INF;
	if(pl < l)
		ret = min(ret, solve(pl, r) + 1);
	if(pr > r)
		ret = min(ret, solve(l, pr) + 1);
	for(int i=l; i<=r; i++){
		if(lb[i] < l && rb[i] > r)
			ret = min(ret, solve(lb[i], rb[i]) + 1);
	}
	return memo[l*KEY + r] = ret;
}
int main(){
	int q, t, i, j, k, x;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d %d", &lb[i], &rb[i]);
	}
	settree(1,1, n);
	scanf("%d", &q);
	while(q--){
		scanf("%d", &x);
		int ans = solve(lb[x], rb[x]) + 1;
		if(ans >= INF/2)
			ans = -1;
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:58:9: warning: unused variable 't' [-Wunused-variable]
   58 |  int q, t, i, j, k, x;
      |         ^
passport.cpp:58:15: warning: unused variable 'j' [-Wunused-variable]
   58 |  int q, t, i, j, k, x;
      |               ^
passport.cpp:58:18: warning: unused variable 'k' [-Wunused-variable]
   58 |  int q, t, i, j, k, x;
      |                  ^
passport.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
passport.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d %d", &lb[i], &rb[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
passport.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 27 ms 8284 KB Output is correct
5 Correct 1047 ms 10280 KB Output is correct
6 Execution timed out 2050 ms 24660 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4700 KB Output is correct
16 Correct 5 ms 4444 KB Output is correct
17 Correct 25 ms 5220 KB Output is correct
18 Correct 285 ms 14016 KB Output is correct
19 Correct 10 ms 4688 KB Output is correct
20 Correct 1610 ms 58284 KB Output is correct
21 Correct 712 ms 23928 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 13 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 3 ms 4700 KB Output is correct
16 Correct 5 ms 4444 KB Output is correct
17 Correct 25 ms 5220 KB Output is correct
18 Correct 285 ms 14016 KB Output is correct
19 Correct 10 ms 4688 KB Output is correct
20 Correct 1610 ms 58284 KB Output is correct
21 Correct 712 ms 23928 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 13 ms 4692 KB Output is correct
25 Correct 1 ms 4536 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 18 ms 4956 KB Output is correct
28 Correct 511 ms 24472 KB Output is correct
29 Execution timed out 2044 ms 88452 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 27 ms 8284 KB Output is correct
5 Correct 1047 ms 10280 KB Output is correct
6 Execution timed out 2050 ms 24660 KB Time limit exceeded
7 Halted 0 ms 0 KB -