Submission #1081815

# Submission time Handle Problem Language Result Execution time Memory
1081815 2024-08-30T11:31:04 Z Thunnus Bitaro’s Party (JOI18_bitaro) C++17
14 / 100
592 ms 475448 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size() 

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	const int SZ = 100;
	int n, m, q, a, b;
	cin >> n >> m >> q;
	vvi adj(n), radj(n);
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		adj[--a].emplace_back(--b);
		radj[b].emplace_back(a);
	}

	vector<vector<pii>> bestSZ(n);
	for(int v = 0; v < n; v++){
		for(int &u : radj[v]){
			for(pii &d : bestSZ[u]){
				bestSZ[v].emplace_back(d.fi + 1, d.se);
			}
		}
		bestSZ[v].emplace_back(0, v);
		sort(bestSZ[v].begin(), bestSZ[v].end(), greater<pii>());
		while(sz(bestSZ[v]) > SZ){
			bestSZ[v].pop_back();
		}
	}

	vb can(n, true);
	while(q--){
		int t, y, ans = -1;
		cin >> t >> y;
		t--;
		vi yi(y);
		for(int i = 0; i < y; i++){
			cin >> yi[i];
			can[--yi[i]] = false;
		}

		if(y >= SZ){
			vi dp(n, -1);
			dp[t] = 0;
			for(int v = t; v >= 0; v--){
				if(dp[v] == -1) continue;
				if(can[v]) ans = max(ans, dp[v]);
				for(int &u : radj[v]){
					dp[u] = max(dp[u], dp[v] + 1);
				}
			}
		}
		else{
			for(pii &p : bestSZ[t]){
				if(can[p.se]){
					ans = p.fi;
					break;
				}
			}
		}
		
		for(int i = 0; i < y; i++){
			can[yi[i]] = true;
		}
		cout << ans << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 4 ms 3420 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 5 ms 3164 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 6 ms 5020 KB Output is correct
10 Correct 5 ms 4956 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 5 ms 4700 KB Output is correct
14 Correct 8 ms 2904 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 3676 KB Output is correct
18 Correct 4 ms 2672 KB Output is correct
19 Correct 4 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 4 ms 3420 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 5 ms 3164 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 6 ms 5020 KB Output is correct
10 Correct 5 ms 4956 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 5 ms 4700 KB Output is correct
14 Correct 8 ms 2904 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 3676 KB Output is correct
18 Correct 4 ms 2672 KB Output is correct
19 Correct 4 ms 3672 KB Output is correct
20 Correct 478 ms 318180 KB Output is correct
21 Correct 492 ms 318204 KB Output is correct
22 Correct 488 ms 317768 KB Output is correct
23 Correct 463 ms 319432 KB Output is correct
24 Correct 535 ms 371028 KB Output is correct
25 Correct 506 ms 372192 KB Output is correct
26 Correct 531 ms 372992 KB Output is correct
27 Correct 506 ms 475224 KB Output is correct
28 Correct 504 ms 475448 KB Output is correct
29 Correct 512 ms 475296 KB Output is correct
30 Correct 509 ms 474448 KB Output is correct
31 Correct 567 ms 450844 KB Output is correct
32 Correct 508 ms 474320 KB Output is correct
33 Correct 453 ms 288596 KB Output is correct
34 Correct 468 ms 255400 KB Output is correct
35 Correct 451 ms 286028 KB Output is correct
36 Correct 419 ms 387668 KB Output is correct
37 Correct 530 ms 351172 KB Output is correct
38 Correct 475 ms 387368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 4 ms 3420 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 5 ms 3164 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 6 ms 5020 KB Output is correct
10 Correct 5 ms 4956 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 5 ms 4700 KB Output is correct
14 Correct 8 ms 2904 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 4 ms 2908 KB Output is correct
17 Correct 4 ms 3676 KB Output is correct
18 Correct 4 ms 2672 KB Output is correct
19 Correct 4 ms 3672 KB Output is correct
20 Correct 478 ms 318180 KB Output is correct
21 Correct 492 ms 318204 KB Output is correct
22 Correct 488 ms 317768 KB Output is correct
23 Correct 463 ms 319432 KB Output is correct
24 Correct 535 ms 371028 KB Output is correct
25 Correct 506 ms 372192 KB Output is correct
26 Correct 531 ms 372992 KB Output is correct
27 Correct 506 ms 475224 KB Output is correct
28 Correct 504 ms 475448 KB Output is correct
29 Correct 512 ms 475296 KB Output is correct
30 Correct 509 ms 474448 KB Output is correct
31 Correct 567 ms 450844 KB Output is correct
32 Correct 508 ms 474320 KB Output is correct
33 Correct 453 ms 288596 KB Output is correct
34 Correct 468 ms 255400 KB Output is correct
35 Correct 451 ms 286028 KB Output is correct
36 Correct 419 ms 387668 KB Output is correct
37 Correct 530 ms 351172 KB Output is correct
38 Correct 475 ms 387368 KB Output is correct
39 Correct 591 ms 367664 KB Output is correct
40 Correct 529 ms 366828 KB Output is correct
41 Correct 592 ms 369216 KB Output is correct
42 Correct 548 ms 372536 KB Output is correct
43 Correct 568 ms 369424 KB Output is correct
44 Incorrect 510 ms 319816 KB Output isn't correct
45 Halted 0 ms 0 KB -