Submission #897940

#TimeUsernameProblemLanguageResultExecution timeMemory
897940duckindogDetecting Molecules (IOI16_molecules)C++14
31 / 100
6 ms2396 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) {}
};
bool f[110][1010];
pair<int, int> trace[110][1010];
vector<int> find_subset(int l, int u, vector<int> w) {
  int n = w.size();

  f[0][w[0]] = f[0][0] = 1;
  for (int i = 1; i < n; ++i) {
    f[i][0] = 1;
    for (int j = 1; j <= u; ++j) {
      auto &ret = f[i][j];
      if (f[i - 1][j]) {
        ret = 1;
        trace[i][j] = {i - 1, j};
      }
      if (j - w[i] >= 0 && f[i - 1][j - w[i]]) {
        ret = 1;
        trace[i][j] = {i - 1, j - w[i]};
      }
    }
  }
  vector<int> answer;
  int i = n - 1, j = 0;
  for (int x = l; x <= u; ++x) if (f[i][x]) j = x;

  if (!j) return answer;

  while (j) {
    int pi, pj; tie(pi, pj) = trace[i][j];
    if (j > pj) answer.push_back(i);
    i = pi; j = pj;
  }
  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);
  }

  for (auto x : find_subset(15, 17, {6, 8, 8, 7}))
    cout << x << ' ';
}
#endif // LOCAL

#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...