Submission #994666

#TimeUsernameProblemLanguageResultExecution timeMemory
994666pavementJobs (BOI24_jobs)C++17
0 / 100
2097 ms33228 KiB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define int long long

using ll = long long;

int N, x[300005], p[300005];
ll s, os, ans;
vector<int> adj[300005];
set<pair<int, ll> > mem;

void bf(int bm, ll sf) {
	if (sf < 0) {
		return;
	}
	if (mem.find(mp(bm, sf)) != mem.end()) {
		return;
	}
	ans = max(ans, sf);
	vector<int> cand;
	for (auto u : adj[0]) {
		if (!(bm & (1 << (u - 1)))) {
			cand.pb(u);
		}
	}
	for (int i = 0; i < N; i++) {
		if (bm & (1 << i)) {
			for (auto u : adj[i + 1]) {
				if (!(bm & (1 << (u - 1)))) {
					cand.pb(u);
				}
			}
		}
	}
	for (auto u : cand) {
		bf(bm | (1 << (u - 1)), sf + x[u]);
	}
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> s;
	os = s;
	for (int i = 1; i <= N; i++) {
		cin >> x[i] >> p[i];
		adj[p[i]].pb(i);
	}
	bf(0, s);
	cout << ans - s << '\n';
}

Compilation message (stderr)

Main.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...