Submission #838190

# Submission time Handle Problem Language Result Execution time Memory
838190 2023-08-26T10:09:13 Z fatemetmhr Passport (JOI23_passport) C++17
48 / 100
2000 ms 4024 KB
// na hanooz omidi vjood dare... hanooz ye karayi hast ke bknm :)

#include <bits/stdc++.h>

using namespace std;


#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x)   (x).begin(), (x).end()
#define fi       first
#define se       second
#define mp       make_pair
#define pb       push_back

typedef long long ll;

const int maxn5 = 2e5 + 10;
const int lg    = 20;

int suf[maxn5], pre[maxn5], ans[maxn5];
int l[maxn5], r[maxn5];
bool mark[maxn5];
pair <int, int> per[maxn5];


int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	int n; cin >> n;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		per[i] = {r[i] - l[i], i};
		l[i]--; r[i]--;
	}
	sort(per, per + n);
	reverse(per, per + n);
	fill(ans, ans + n + 5, maxn5);
	for(int i = 0; i < n; i++){
		int v = per[i].se;
		int cnt = 0;
		int lq = l[v], pt = r[v];
		bool con = true;
		while(con && lq > 0){
			con = false;
			cnt++;
			int keepl = lq;
			while(pt >= keepl){
				con = true;
				lq = min(lq, l[pt]);
				ans[v] = min(ans[v], ans[pt] + cnt);
				pt--;
			}
		}
		if(lq > 0)
			cnt = maxn5;
		int keep = cnt;
		cnt = 0;
		int rq = r[v]; pt = l[v];
		con = true;
		while(rq < n - 1 && con){
			con = false;
			cnt++;
			int keepr = rq;
			while(pt <= keepr){
				con = true;
				rq = max(rq, r[pt]);
				ans[v] = min(ans[v], ans[pt] + cnt);
				pt++;
			}
		}
		if(rq < n - 1)
			cnt = maxn5;
		ans[v] = min(ans[v], cnt + keep);
	}

	int q; cin >> q;
	for(int i = 0; i < q; i++){
		int x; cin >> x;
		x--;
		cout << (ans[x] >= maxn5 ? -1 : ans[x] + 1) << '\n';
	}

}





















# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2073 ms 4024 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 10 ms 340 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 10 ms 416 KB Output is correct
20 Correct 13 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 5 ms 340 KB Output is correct
24 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 10 ms 340 KB Output is correct
18 Correct 12 ms 340 KB Output is correct
19 Correct 10 ms 416 KB Output is correct
20 Correct 13 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 5 ms 340 KB Output is correct
24 Correct 7 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 3 ms 432 KB Output is correct
31 Correct 4 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2073 ms 4024 KB Time limit exceeded
5 Halted 0 ms 0 KB -