답안 #59448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59448 2018-07-22T05:29:19 Z tmwilliamlin168 Bitaro’s Party (JOI18_bitaro) C++14
14 / 100
1387 ms 23208 KB
#include <bits/stdc++.h>
using namespace std;

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

const int mxN=1e5, bs=15;
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";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5048 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5136 KB Output is correct
4 Correct 6 ms 5160 KB Output is correct
5 Correct 9 ms 5336 KB Output is correct
6 Correct 9 ms 5412 KB Output is correct
7 Correct 10 ms 5412 KB Output is correct
8 Correct 9 ms 5456 KB Output is correct
9 Correct 9 ms 5456 KB Output is correct
10 Correct 10 ms 5456 KB Output is correct
11 Correct 9 ms 5456 KB Output is correct
12 Correct 11 ms 5484 KB Output is correct
13 Correct 9 ms 5484 KB Output is correct
14 Correct 8 ms 5484 KB Output is correct
15 Correct 8 ms 5484 KB Output is correct
16 Correct 7 ms 5484 KB Output is correct
17 Correct 9 ms 5484 KB Output is correct
18 Correct 8 ms 5484 KB Output is correct
19 Correct 8 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5048 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5136 KB Output is correct
4 Correct 6 ms 5160 KB Output is correct
5 Correct 9 ms 5336 KB Output is correct
6 Correct 9 ms 5412 KB Output is correct
7 Correct 10 ms 5412 KB Output is correct
8 Correct 9 ms 5456 KB Output is correct
9 Correct 9 ms 5456 KB Output is correct
10 Correct 10 ms 5456 KB Output is correct
11 Correct 9 ms 5456 KB Output is correct
12 Correct 11 ms 5484 KB Output is correct
13 Correct 9 ms 5484 KB Output is correct
14 Correct 8 ms 5484 KB Output is correct
15 Correct 8 ms 5484 KB Output is correct
16 Correct 7 ms 5484 KB Output is correct
17 Correct 9 ms 5484 KB Output is correct
18 Correct 8 ms 5484 KB Output is correct
19 Correct 8 ms 5484 KB Output is correct
20 Correct 160 ms 6556 KB Output is correct
21 Correct 166 ms 6556 KB Output is correct
22 Correct 160 ms 6636 KB Output is correct
23 Correct 162 ms 6636 KB Output is correct
24 Correct 344 ms 20672 KB Output is correct
25 Correct 322 ms 20672 KB Output is correct
26 Correct 312 ms 20672 KB Output is correct
27 Correct 332 ms 23164 KB Output is correct
28 Correct 304 ms 23164 KB Output is correct
29 Correct 302 ms 23208 KB Output is correct
30 Correct 301 ms 23208 KB Output is correct
31 Correct 337 ms 23208 KB Output is correct
32 Correct 304 ms 23208 KB Output is correct
33 Correct 261 ms 23208 KB Output is correct
34 Correct 246 ms 23208 KB Output is correct
35 Correct 252 ms 23208 KB Output is correct
36 Correct 289 ms 23208 KB Output is correct
37 Correct 309 ms 23208 KB Output is correct
38 Correct 248 ms 23208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5048 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 7 ms 5136 KB Output is correct
4 Correct 6 ms 5160 KB Output is correct
5 Correct 9 ms 5336 KB Output is correct
6 Correct 9 ms 5412 KB Output is correct
7 Correct 10 ms 5412 KB Output is correct
8 Correct 9 ms 5456 KB Output is correct
9 Correct 9 ms 5456 KB Output is correct
10 Correct 10 ms 5456 KB Output is correct
11 Correct 9 ms 5456 KB Output is correct
12 Correct 11 ms 5484 KB Output is correct
13 Correct 9 ms 5484 KB Output is correct
14 Correct 8 ms 5484 KB Output is correct
15 Correct 8 ms 5484 KB Output is correct
16 Correct 7 ms 5484 KB Output is correct
17 Correct 9 ms 5484 KB Output is correct
18 Correct 8 ms 5484 KB Output is correct
19 Correct 8 ms 5484 KB Output is correct
20 Correct 160 ms 6556 KB Output is correct
21 Correct 166 ms 6556 KB Output is correct
22 Correct 160 ms 6636 KB Output is correct
23 Correct 162 ms 6636 KB Output is correct
24 Correct 344 ms 20672 KB Output is correct
25 Correct 322 ms 20672 KB Output is correct
26 Correct 312 ms 20672 KB Output is correct
27 Correct 332 ms 23164 KB Output is correct
28 Correct 304 ms 23164 KB Output is correct
29 Correct 302 ms 23208 KB Output is correct
30 Correct 301 ms 23208 KB Output is correct
31 Correct 337 ms 23208 KB Output is correct
32 Correct 304 ms 23208 KB Output is correct
33 Correct 261 ms 23208 KB Output is correct
34 Correct 246 ms 23208 KB Output is correct
35 Correct 252 ms 23208 KB Output is correct
36 Correct 289 ms 23208 KB Output is correct
37 Correct 309 ms 23208 KB Output is correct
38 Correct 248 ms 23208 KB Output is correct
39 Correct 369 ms 23208 KB Output is correct
40 Correct 965 ms 23208 KB Output is correct
41 Correct 1387 ms 23208 KB Output is correct
42 Correct 352 ms 23208 KB Output is correct
43 Correct 331 ms 23208 KB Output is correct
44 Incorrect 211 ms 23208 KB Output isn't correct
45 Halted 0 ms 0 KB -