Submission #772128

#TimeUsernameProblemLanguageResultExecution timeMemory
772128Tkm_algoDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms468 KiB
#include "bits/stdc++.h"
#include "molecules.h"

using namespace std;
using ll = long long;
const int N = 1e4 + 10;

vector<int> find_subset(int l, int u, vector<int> w) {
	vector<int> v(N);
	v[0] = 1;
	for (int y = 0; y < w.size(); y++) {
		int x = w[y];
		for (int i = N - 1; i >= 0; i--) {
			if (v[i] && i + x < N) {
				v[i + x] = y;
			}
		}
	}
	int res = 0;
	for (int i = l; i <= u; i++) {
		if (v[i]) {
			res = i;
			break;
		}
	}
	vector<int> ans;
	while (res != 0) {
		ans.push_back(v[res]);
		res -= w[v[res]];
	}
	return ans;
}

// int main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);
	
// 	int l, u;
// 	cin >> l >> u;
// 	int n;
// 	cin >> n;
// 	vector<int> w;
// 	for (int i = 0; i < n; i++) {
// 		int x;
// 		cin >> x;
// 		w.push_back(x);
// 	}
// 	vector<int> ans = find_subset(l, u, w);
// 	for (auto x : ans) {
// 		cout << x << ' ';
// 	}
// }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for (int y = 0; y < w.size(); y++) {
      |                  ~~^~~~~~~~~~
#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...