Submission #410626

# Submission time Handle Problem Language Result Execution time Memory
410626 2021-05-23T07:41:26 Z Namnamseo Bitaro’s Party (JOI18_bitaro) C++17
100 / 100
1024 ms 210912 KB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
using pp=pair<int, int>;
const int maxn = int(1e5) + 10;
const int B = 200;

int n, m, q;
vector<int> re[maxn];

vector<pp> prec[maxn];

int seen[maxn];
int nt;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> q;
	for (int i=1; i<=m; ++i) {
		int s, e; cin >> s >> e;
		re[e].push_back(s);
	}

	for (int i=1; i<=n; ++i) {
		prec[i].push_back({0, i});
		for (int j:re[i]) {
			static vector<pp> tmp; tmp.clear();
			vector<pp> &v1 = prec[i], &v2 = prec[j];
			int i1 = 0, i2 = 0;
			int s1 = int(v1.size()), s2 = int(v2.size());
			++nt;
			while (int(tmp.size()) < B && (i1 < s1 || i2 < s2)) {
				if (i1 < s1 && (i2 == s2 || v1[i1].first >= v2[i2].first+1)) {
					if (seen[v1[i1].second] != nt) {
						tmp.push_back(v1[i1]);
					}
					++i1;
				} else {
					if (seen[v2[i2].second] != nt) {
						tmp.push_back(v2[i2]);
						++tmp.back().first;
					}
					++i2;
				}
				seen[tmp.back().second] = nt;
			}
			swap(v1, tmp);
		}
	}

	for (;q--;) {
		int dest, igs; cin >> dest >> igs;
		static int ign[maxn];
		++nt;
		for (int i=0; i<igs; ++i) {
			cin >> ign[i];
			seen[ign[i]] = nt;
		}

		if (igs < B) {
			bool found = 0;
			for (auto [dist, from]:prec[dest]) {
				if (seen[from] != nt) {
					cout << dist << '\n';
					found = 1;
					break;
				}
			}
			if (!found) {
				cout << "-1\n";
			}
			continue;
		}

		static int qd[maxn];
		fill(qd+1, qd+dest+1, -1);
		int ans = -1;
		qd[dest] = 0;
		for (int i=dest; 1<=i; --i) if (qd[i] != -1) {
			if (seen[i] != nt) {
				ans = max(ans, qd[i]);
			}
			for (int j:re[i]) {
				qd[j] = max(qd[j], qd[i]+1);
			}
		}

		cout << ans << '\n';
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 6 ms 5452 KB Output is correct
6 Correct 6 ms 5580 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 10 ms 6860 KB Output is correct
9 Correct 10 ms 6860 KB Output is correct
10 Correct 11 ms 6788 KB Output is correct
11 Correct 10 ms 6732 KB Output is correct
12 Correct 8 ms 6220 KB Output is correct
13 Correct 10 ms 6656 KB Output is correct
14 Correct 8 ms 6220 KB Output is correct
15 Correct 7 ms 5708 KB Output is correct
16 Correct 8 ms 6196 KB Output is correct
17 Correct 8 ms 6476 KB Output is correct
18 Correct 7 ms 5964 KB Output is correct
19 Correct 8 ms 6476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 6 ms 5452 KB Output is correct
6 Correct 6 ms 5580 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 10 ms 6860 KB Output is correct
9 Correct 10 ms 6860 KB Output is correct
10 Correct 11 ms 6788 KB Output is correct
11 Correct 10 ms 6732 KB Output is correct
12 Correct 8 ms 6220 KB Output is correct
13 Correct 10 ms 6656 KB Output is correct
14 Correct 8 ms 6220 KB Output is correct
15 Correct 7 ms 5708 KB Output is correct
16 Correct 8 ms 6196 KB Output is correct
17 Correct 8 ms 6476 KB Output is correct
18 Correct 7 ms 5964 KB Output is correct
19 Correct 8 ms 6476 KB Output is correct
20 Correct 456 ms 7976 KB Output is correct
21 Correct 409 ms 8004 KB Output is correct
22 Correct 459 ms 8056 KB Output is correct
23 Correct 446 ms 8004 KB Output is correct
24 Correct 602 ms 163684 KB Output is correct
25 Correct 613 ms 166872 KB Output is correct
26 Correct 606 ms 166980 KB Output is correct
27 Correct 682 ms 210716 KB Output is correct
28 Correct 690 ms 210736 KB Output is correct
29 Correct 682 ms 210788 KB Output is correct
30 Correct 694 ms 210368 KB Output is correct
31 Correct 700 ms 205872 KB Output is correct
32 Correct 691 ms 210316 KB Output is correct
33 Correct 487 ms 145032 KB Output is correct
34 Correct 464 ms 127172 KB Output is correct
35 Correct 484 ms 144396 KB Output is correct
36 Correct 557 ms 179192 KB Output is correct
37 Correct 544 ms 169412 KB Output is correct
38 Correct 569 ms 179296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 6 ms 5452 KB Output is correct
6 Correct 6 ms 5580 KB Output is correct
7 Correct 6 ms 5452 KB Output is correct
8 Correct 10 ms 6860 KB Output is correct
9 Correct 10 ms 6860 KB Output is correct
10 Correct 11 ms 6788 KB Output is correct
11 Correct 10 ms 6732 KB Output is correct
12 Correct 8 ms 6220 KB Output is correct
13 Correct 10 ms 6656 KB Output is correct
14 Correct 8 ms 6220 KB Output is correct
15 Correct 7 ms 5708 KB Output is correct
16 Correct 8 ms 6196 KB Output is correct
17 Correct 8 ms 6476 KB Output is correct
18 Correct 7 ms 5964 KB Output is correct
19 Correct 8 ms 6476 KB Output is correct
20 Correct 456 ms 7976 KB Output is correct
21 Correct 409 ms 8004 KB Output is correct
22 Correct 459 ms 8056 KB Output is correct
23 Correct 446 ms 8004 KB Output is correct
24 Correct 602 ms 163684 KB Output is correct
25 Correct 613 ms 166872 KB Output is correct
26 Correct 606 ms 166980 KB Output is correct
27 Correct 682 ms 210716 KB Output is correct
28 Correct 690 ms 210736 KB Output is correct
29 Correct 682 ms 210788 KB Output is correct
30 Correct 694 ms 210368 KB Output is correct
31 Correct 700 ms 205872 KB Output is correct
32 Correct 691 ms 210316 KB Output is correct
33 Correct 487 ms 145032 KB Output is correct
34 Correct 464 ms 127172 KB Output is correct
35 Correct 484 ms 144396 KB Output is correct
36 Correct 557 ms 179192 KB Output is correct
37 Correct 544 ms 169412 KB Output is correct
38 Correct 569 ms 179296 KB Output is correct
39 Correct 655 ms 164464 KB Output is correct
40 Correct 623 ms 165352 KB Output is correct
41 Correct 616 ms 165264 KB Output is correct
42 Correct 619 ms 165980 KB Output is correct
43 Correct 604 ms 165444 KB Output is correct
44 Correct 486 ms 8392 KB Output is correct
45 Correct 469 ms 7992 KB Output is correct
46 Correct 459 ms 8060 KB Output is correct
47 Correct 491 ms 8132 KB Output is correct
48 Correct 458 ms 8068 KB Output is correct
49 Correct 731 ms 210500 KB Output is correct
50 Correct 684 ms 209900 KB Output is correct
51 Correct 457 ms 8360 KB Output is correct
52 Correct 434 ms 7908 KB Output is correct
53 Correct 607 ms 178900 KB Output is correct
54 Correct 597 ms 169908 KB Output is correct
55 Correct 569 ms 178372 KB Output is correct
56 Correct 551 ms 169912 KB Output is correct
57 Correct 486 ms 8368 KB Output is correct
58 Correct 499 ms 8296 KB Output is correct
59 Correct 459 ms 7968 KB Output is correct
60 Correct 466 ms 8004 KB Output is correct
61 Correct 791 ms 210416 KB Output is correct
62 Correct 616 ms 179268 KB Output is correct
63 Correct 580 ms 169420 KB Output is correct
64 Correct 1024 ms 210608 KB Output is correct
65 Correct 749 ms 178920 KB Output is correct
66 Correct 652 ms 170260 KB Output is correct
67 Correct 963 ms 210512 KB Output is correct
68 Correct 712 ms 179312 KB Output is correct
69 Correct 637 ms 168804 KB Output is correct
70 Correct 705 ms 210532 KB Output is correct
71 Correct 568 ms 179212 KB Output is correct
72 Correct 556 ms 169648 KB Output is correct
73 Correct 723 ms 210368 KB Output is correct
74 Correct 590 ms 179204 KB Output is correct
75 Correct 569 ms 169744 KB Output is correct
76 Correct 738 ms 210912 KB Output is correct
77 Correct 717 ms 210640 KB Output is correct
78 Correct 690 ms 210756 KB Output is correct
79 Correct 456 ms 8404 KB Output is correct
80 Correct 435 ms 8020 KB Output is correct
81 Correct 419 ms 8004 KB Output is correct
82 Correct 734 ms 210912 KB Output is correct
83 Correct 735 ms 205892 KB Output is correct
84 Correct 716 ms 210584 KB Output is correct
85 Correct 711 ms 205636 KB Output is correct
86 Correct 702 ms 210588 KB Output is correct
87 Correct 708 ms 206148 KB Output is correct
88 Correct 490 ms 8452 KB Output is correct
89 Correct 499 ms 8404 KB Output is correct
90 Correct 475 ms 8260 KB Output is correct
91 Correct 477 ms 8024 KB Output is correct
92 Correct 460 ms 8004 KB Output is correct
93 Correct 451 ms 8024 KB Output is correct
94 Correct 532 ms 145364 KB Output is correct
95 Correct 518 ms 126468 KB Output is correct
96 Correct 519 ms 144324 KB Output is correct
97 Correct 472 ms 128068 KB Output is correct
98 Correct 506 ms 144752 KB Output is correct
99 Correct 462 ms 127684 KB Output is correct
100 Correct 489 ms 8388 KB Output is correct
101 Correct 477 ms 8388 KB Output is correct
102 Correct 470 ms 7948 KB Output is correct
103 Correct 467 ms 8132 KB Output is correct
104 Correct 457 ms 8004 KB Output is correct
105 Correct 456 ms 8016 KB Output is correct
106 Correct 611 ms 178996 KB Output is correct
107 Correct 595 ms 169796 KB Output is correct
108 Correct 586 ms 179408 KB Output is correct
109 Correct 563 ms 169644 KB Output is correct
110 Correct 571 ms 179372 KB Output is correct
111 Correct 562 ms 170028 KB Output is correct
112 Correct 490 ms 8456 KB Output is correct
113 Correct 484 ms 8392 KB Output is correct
114 Correct 459 ms 8004 KB Output is correct
115 Correct 474 ms 8004 KB Output is correct
116 Correct 450 ms 7912 KB Output is correct
117 Correct 462 ms 8004 KB Output is correct
118 Correct 678 ms 209988 KB Output is correct
119 Correct 566 ms 179012 KB Output is correct
120 Correct 552 ms 169284 KB Output is correct
121 Correct 688 ms 209988 KB Output is correct
122 Correct 557 ms 178500 KB Output is correct
123 Correct 554 ms 169072 KB Output is correct
124 Correct 689 ms 210004 KB Output is correct
125 Correct 560 ms 179268 KB Output is correct
126 Correct 548 ms 168772 KB Output is correct