Submission #59445

# Submission time Handle Problem Language Result Execution time Memory
59445 2018-07-22T05:27:35 Z tmwilliamlin168 Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
1500 ms 60800 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define fi first
#define se second

const int mxN=1e5, bs=40;
int n, m, q, dp2[mxN], c[mxN];
vector<int> adj[mxN];
vector<pii> dp1[mxN];
priority_queue<pii, vector<pii>, greater<pii>> pq;
bool a[mxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> q;
	while(m--) {
		int u, v;
		cin >> u >> v, --u, --v;
		adj[v].push_back(u);
	}
	for(int i=0; i<n; ++i) {
		pq.push({0, i});
		for(int v : adj[i]) {
			for(pii p : dp1[v]) {
				pq.push({p.fi+1, p.se});
				if(pq.size()>bs)
					pq.pop();
			}
		}
		while(!pq.empty()) {
			dp1[i].push_back(pq.top());
			pq.pop();
		}
	}
	while(q--) {
		int t, y, ans=-1;
		cin >> t >> y, --t;
		for(int i=0; i<y; ++i) {
			cin >> c[i], --c[i];
			a[c[i]]=1;
		}
		if(y>bs) {
			memset(dp2, -1, 4*(t+1));
			for(int i=0; i<=t; ++i) {
				dp2[i]=a[i]?-n:0;
				for(int v : adj[i])
					dp2[i]=max(dp2[v]+1, dp2[i]);
			}
			ans=max(dp2[t], ans);
		} else {
			for(int i=dp1[t].size()-1; i>=0; --i) {
				if(a[dp1[t][i].se])
					continue;
				ans=dp1[t][i].fi;
				break;
			}
		}
		for(int i=0; i<y; ++i)
			a[c[i]]=0;
		cout << ans << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 6 ms 5192 KB Output is correct
5 Correct 13 ms 5748 KB Output is correct
6 Correct 12 ms 5748 KB Output is correct
7 Correct 13 ms 5748 KB Output is correct
8 Correct 10 ms 5796 KB Output is correct
9 Correct 11 ms 5796 KB Output is correct
10 Correct 12 ms 5836 KB Output is correct
11 Correct 12 ms 5868 KB Output is correct
12 Correct 12 ms 5868 KB Output is correct
13 Correct 12 ms 5868 KB Output is correct
14 Correct 11 ms 5868 KB Output is correct
15 Correct 11 ms 5868 KB Output is correct
16 Correct 9 ms 5868 KB Output is correct
17 Correct 12 ms 5868 KB Output is correct
18 Correct 13 ms 5868 KB Output is correct
19 Correct 12 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 6 ms 5192 KB Output is correct
5 Correct 13 ms 5748 KB Output is correct
6 Correct 12 ms 5748 KB Output is correct
7 Correct 13 ms 5748 KB Output is correct
8 Correct 10 ms 5796 KB Output is correct
9 Correct 11 ms 5796 KB Output is correct
10 Correct 12 ms 5836 KB Output is correct
11 Correct 12 ms 5868 KB Output is correct
12 Correct 12 ms 5868 KB Output is correct
13 Correct 12 ms 5868 KB Output is correct
14 Correct 11 ms 5868 KB Output is correct
15 Correct 11 ms 5868 KB Output is correct
16 Correct 9 ms 5868 KB Output is correct
17 Correct 12 ms 5868 KB Output is correct
18 Correct 13 ms 5868 KB Output is correct
19 Correct 12 ms 5868 KB Output is correct
20 Correct 389 ms 6900 KB Output is correct
21 Correct 375 ms 7032 KB Output is correct
22 Correct 384 ms 7032 KB Output is correct
23 Correct 378 ms 7124 KB Output is correct
24 Correct 764 ms 50476 KB Output is correct
25 Correct 718 ms 50540 KB Output is correct
26 Correct 713 ms 50540 KB Output is correct
27 Correct 671 ms 60712 KB Output is correct
28 Correct 674 ms 60800 KB Output is correct
29 Correct 705 ms 60800 KB Output is correct
30 Correct 657 ms 60800 KB Output is correct
31 Correct 762 ms 60800 KB Output is correct
32 Correct 664 ms 60800 KB Output is correct
33 Correct 482 ms 60800 KB Output is correct
34 Correct 510 ms 60800 KB Output is correct
35 Correct 536 ms 60800 KB Output is correct
36 Correct 533 ms 60800 KB Output is correct
37 Correct 704 ms 60800 KB Output is correct
38 Correct 609 ms 60800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 6 ms 5192 KB Output is correct
5 Correct 13 ms 5748 KB Output is correct
6 Correct 12 ms 5748 KB Output is correct
7 Correct 13 ms 5748 KB Output is correct
8 Correct 10 ms 5796 KB Output is correct
9 Correct 11 ms 5796 KB Output is correct
10 Correct 12 ms 5836 KB Output is correct
11 Correct 12 ms 5868 KB Output is correct
12 Correct 12 ms 5868 KB Output is correct
13 Correct 12 ms 5868 KB Output is correct
14 Correct 11 ms 5868 KB Output is correct
15 Correct 11 ms 5868 KB Output is correct
16 Correct 9 ms 5868 KB Output is correct
17 Correct 12 ms 5868 KB Output is correct
18 Correct 13 ms 5868 KB Output is correct
19 Correct 12 ms 5868 KB Output is correct
20 Correct 389 ms 6900 KB Output is correct
21 Correct 375 ms 7032 KB Output is correct
22 Correct 384 ms 7032 KB Output is correct
23 Correct 378 ms 7124 KB Output is correct
24 Correct 764 ms 50476 KB Output is correct
25 Correct 718 ms 50540 KB Output is correct
26 Correct 713 ms 50540 KB Output is correct
27 Correct 671 ms 60712 KB Output is correct
28 Correct 674 ms 60800 KB Output is correct
29 Correct 705 ms 60800 KB Output is correct
30 Correct 657 ms 60800 KB Output is correct
31 Correct 762 ms 60800 KB Output is correct
32 Correct 664 ms 60800 KB Output is correct
33 Correct 482 ms 60800 KB Output is correct
34 Correct 510 ms 60800 KB Output is correct
35 Correct 536 ms 60800 KB Output is correct
36 Correct 533 ms 60800 KB Output is correct
37 Correct 704 ms 60800 KB Output is correct
38 Correct 609 ms 60800 KB Output is correct
39 Correct 827 ms 60800 KB Output is correct
40 Correct 732 ms 60800 KB Output is correct
41 Correct 1500 ms 60800 KB Output is correct
42 Correct 833 ms 60800 KB Output is correct
43 Correct 787 ms 60800 KB Output is correct
44 Incorrect 430 ms 60800 KB Output isn't correct
45 Halted 0 ms 0 KB -