Submission #898049

#TimeUsernameProblemLanguageResultExecution timeMemory
898049duckindogDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms856 KiB
// from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

//#define LOCAL

#ifndef LOCAL
#include "molecules.h"
#endif // LOCAL

struct T {
  int a, b;

  T(int aa, int bb) : a(aa), b(bb) {}
};
const int N = 1e4 + 2;
int f[N];
bool dd[N];

vector<int> find_subset(int l, int u, vector<int> w) {
  int n = w.size();
  memset(f, -1, sizeof f);
  f[0] = 0;
  for (int i = 1; i <= u; ++i) {
    int &ret = f[i];
    for (int j = n; j >= 1; --j) {
      if (i - w[j - 1] < 0) continue;
      if (f[i - w[j - 1]] > - 1 && f[i - w[j - 1]] < j) f[i] = j;
    }
  }
  int j = 0;
  for (int i = 1; i <= u; ++i) if (f[i] > -1) j = i;
  vector<int> answer;

  while (j > 0) {
    cerr << j << '\n';
    answer.push_back(f[j] - 1);
    j = j - w[f[j] - 1];
  }

  return answer;

}

#ifdef LOCAL
int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }

  int l, u; cin >> l >> u;
  int x;
  vector<int> input;
  while (cin >> x) input.push_back(x);

  for (auto i : find_subset(l, u, input))
    cout << i << ' ';
}
#endif // LOCAL

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:26:10: warning: unused variable 'ret' [-Wunused-variable]
   26 |     int &ret = f[i];
      |          ^~~
#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...