Submission #1222309

#TimeUsernameProblemLanguageResultExecution timeMemory
1222309viduxDetecting Molecules (IOI16_molecules)C++17
0 / 100
0 ms328 KiB
#include "molecules.h"

#include <bits/stdc++.h>
#define fi first
#define se second
#define ALL(x) (x.begin()), (x.end())
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_ARR(x) cerr << #x << ": "; for (auto &y : x) cout << y << " "; cout << endl;
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
	sort(ALL(w));
	int n = SZ(w);
	vector<pii> dp(u+1, {-1, -1}); // {prev, added}
	dp[0] = {0, -1};
	int ok = 0;
	for (int i = 0; i < n; i++) {
		vector<pii> dp2 = dp;
		for (int pw = u-1; pw >= 0; pw--) {
			int nw = w[i]+pw;
			if (nw > u || dp[pw].fi == -1) continue;
			dp2[nw] = {pw, i};
			if (nw >= l && nw <= u) {
				ok = nw;
				break;
			}
		}
		swap(dp, dp2);
		if (ok) break;
	}
	vi ans;
	if (!ok) return ans;
	ans.reserve(n);
	while (ok) {
		if (dp[ok].se == -1) continue;
		ans.push_back(dp[ok].se);
		ok = dp[ok].fi;
	}
	return ans;
}

// n^2 dp -> 31pts

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...