Submission #1031928

# Submission time Handle Problem Language Result Execution time Memory
1031928 2024-07-23T08:44:59 Z juicy Bitaro’s Party (JOI18_bitaro) C++17
14 / 100
959 ms 414840 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	const int S = 320, inf = 1e9;

	int N, M, Q; cin >> N >> M >> Q;
	vector<vector<int>> g(N);
	while (M--) {
		int u, v; cin >> u >> v; --u, --v;
		g[u].push_back(v);
	}
	vector<vector<array<int, 2>>> cands(N);
	vector<bool> vs(N);
	auto mrg = [&](vector<array<int, 2>> A, vector<array<int, 2>> B) {
		vector<array<int, 2>> res;
		auto add = [&](const array<int, 2> &elem) {
			if (!vs[elem[1]]) {
				res.push_back(elem);
				vs[elem[1]] = 1;
			}
		};
		for (auto &x : A) {
			++x[0];
		}
		for (int i = 0, j = 0; res.size() + 1 < S && (i < A.size() || j < B.size()); ) {
			if (i == A.size()) {
				add(B[j++]);
			} else if (j == B.size()) {
				add(A[i++]);
			} else if (A[i][0] > B[j][0]) {
				add(A[i++]);
			} else {
				add(B[j++]);
			}
		} 
		for (auto &x : res) {
			vs[x[1]] = 0;
		}
		return res;
	};
	for (int i = 0; i < N; ++i) {
		cands[i] = mrg({{-1, i}}, cands[i]);
		for (int j : g[i]) {
			cands[j] = mrg(cands[i], cands[j]);
		}
	}
	vector<int> dp(N);
	while (Q--) {
		int T, Y; cin >> T >> Y; --T;
		vector<int> C(Y);
		for (int &x : C) {
			cin >> x; --x;
			vs[x] = 1;
		}
		if (Y >= S) {
			fill(dp.begin(), dp.end(), -inf);
			for (int i = 0; i < N; ++i) {
				if (!vs[i]) {
					dp[i] = max(dp[i], 0);
				}
				for (int j : g[i]) {
					dp[j] = max(dp[j], dp[i] + 1);
				}
			}
			cout << (dp[T] >= 0 ? dp[T] : -1) << "\n";
		} else {
			int res = -1;
			for (auto &x : cands[T]) {
				if (!vs[x[1]]) {
					res = x[0];
					break;
				}
			}
			cout << res << "\n";
		}
		for (int &x : C) {
			vs[x] = 0;
		}
	}
	return 0;
}

Compilation message

bitaro.cpp: In lambda function:
bitaro.cpp:35:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0, j = 0; res.size() + 1 < S && (i < A.size() || j < B.size()); ) {
      |                                                 ~~^~~~~~~~~~
bitaro.cpp:35:67: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0, j = 0; res.size() + 1 < S && (i < A.size() || j < B.size()); ) {
      |                                                                 ~~^~~~~~~~~~
bitaro.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    if (i == A.size()) {
      |        ~~^~~~~~~~~~~
bitaro.cpp:38:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    } else if (j == B.size()) {
      |               ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 7 ms 3932 KB Output is correct
9 Correct 7 ms 4188 KB Output is correct
10 Correct 8 ms 4188 KB Output is correct
11 Correct 6 ms 3676 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 6 ms 3672 KB Output is correct
14 Correct 6 ms 2588 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 5 ms 2392 KB Output is correct
17 Correct 6 ms 2652 KB Output is correct
18 Correct 4 ms 1628 KB Output is correct
19 Correct 7 ms 2692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 7 ms 3932 KB Output is correct
9 Correct 7 ms 4188 KB Output is correct
10 Correct 8 ms 4188 KB Output is correct
11 Correct 6 ms 3676 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 6 ms 3672 KB Output is correct
14 Correct 6 ms 2588 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 5 ms 2392 KB Output is correct
17 Correct 6 ms 2652 KB Output is correct
18 Correct 4 ms 1628 KB Output is correct
19 Correct 7 ms 2692 KB Output is correct
20 Correct 401 ms 6996 KB Output is correct
21 Correct 346 ms 6992 KB Output is correct
22 Correct 385 ms 6992 KB Output is correct
23 Correct 493 ms 6900 KB Output is correct
24 Correct 647 ms 258644 KB Output is correct
25 Correct 616 ms 269652 KB Output is correct
26 Correct 649 ms 269400 KB Output is correct
27 Correct 810 ms 413780 KB Output is correct
28 Correct 800 ms 413852 KB Output is correct
29 Correct 832 ms 413852 KB Output is correct
30 Correct 819 ms 413048 KB Output is correct
31 Correct 793 ms 402756 KB Output is correct
32 Correct 873 ms 412756 KB Output is correct
33 Correct 609 ms 256080 KB Output is correct
34 Correct 483 ms 211536 KB Output is correct
35 Correct 628 ms 254312 KB Output is correct
36 Correct 762 ms 334644 KB Output is correct
37 Correct 661 ms 305232 KB Output is correct
38 Correct 850 ms 335860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 7 ms 3932 KB Output is correct
9 Correct 7 ms 4188 KB Output is correct
10 Correct 8 ms 4188 KB Output is correct
11 Correct 6 ms 3676 KB Output is correct
12 Correct 4 ms 1880 KB Output is correct
13 Correct 6 ms 3672 KB Output is correct
14 Correct 6 ms 2588 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 5 ms 2392 KB Output is correct
17 Correct 6 ms 2652 KB Output is correct
18 Correct 4 ms 1628 KB Output is correct
19 Correct 7 ms 2692 KB Output is correct
20 Correct 401 ms 6996 KB Output is correct
21 Correct 346 ms 6992 KB Output is correct
22 Correct 385 ms 6992 KB Output is correct
23 Correct 493 ms 6900 KB Output is correct
24 Correct 647 ms 258644 KB Output is correct
25 Correct 616 ms 269652 KB Output is correct
26 Correct 649 ms 269400 KB Output is correct
27 Correct 810 ms 413780 KB Output is correct
28 Correct 800 ms 413852 KB Output is correct
29 Correct 832 ms 413852 KB Output is correct
30 Correct 819 ms 413048 KB Output is correct
31 Correct 793 ms 402756 KB Output is correct
32 Correct 873 ms 412756 KB Output is correct
33 Correct 609 ms 256080 KB Output is correct
34 Correct 483 ms 211536 KB Output is correct
35 Correct 628 ms 254312 KB Output is correct
36 Correct 762 ms 334644 KB Output is correct
37 Correct 661 ms 305232 KB Output is correct
38 Correct 850 ms 335860 KB Output is correct
39 Correct 697 ms 263224 KB Output is correct
40 Correct 790 ms 264436 KB Output is correct
41 Correct 730 ms 267520 KB Output is correct
42 Correct 805 ms 265156 KB Output is correct
43 Correct 660 ms 264528 KB Output is correct
44 Correct 421 ms 8220 KB Output is correct
45 Correct 376 ms 7436 KB Output is correct
46 Correct 380 ms 7252 KB Output is correct
47 Correct 386 ms 7172 KB Output is correct
48 Correct 359 ms 7044 KB Output is correct
49 Correct 765 ms 414840 KB Output is correct
50 Correct 752 ms 413480 KB Output is correct
51 Correct 418 ms 8016 KB Output is correct
52 Correct 364 ms 7160 KB Output is correct
53 Correct 807 ms 334416 KB Output is correct
54 Correct 610 ms 306260 KB Output is correct
55 Correct 739 ms 333652 KB Output is correct
56 Correct 616 ms 306404 KB Output is correct
57 Correct 434 ms 8196 KB Output is correct
58 Correct 418 ms 8000 KB Output is correct
59 Correct 487 ms 7172 KB Output is correct
60 Correct 489 ms 7252 KB Output is correct
61 Correct 959 ms 413620 KB Output is correct
62 Correct 930 ms 335064 KB Output is correct
63 Correct 761 ms 304540 KB Output is correct
64 Incorrect 935 ms 413656 KB Output isn't correct
65 Halted 0 ms 0 KB -