Submission #299427

# Submission time Handle Problem Language Result Execution time Memory
299427 2020-09-14T22:01:37 Z sandoval Detecting Molecules (IOI16_molecules) C++11
0 / 100
50 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;
using ll = long long;

constexpr int MAXN = 5+1e4;
constexpr ll INF = 1LL<<50;

ll memo[MAXN][MAXN];

ll dp(int i, int s, const vector<int>& w) {
  const int n = (int)w.size();
  if (s <= 0) return 0;
  if (i == n) return INF;
  ll& ans = memo[i][s];
  if (ans != -1) return ans;
  return ans = min(dp(1+i,s,w), w[i]+dp(1+i, s-w[i], w));
}

void go(int i, int s, const vector<int>& w, vector<int>& res) {
  const int n = (int)w.size();
  if (i == n || s <= 0) return;
  const ll d = dp(i,s,w);
  if (dp(1+i,s,w) == d) {
    go(1+i, s, w, res);
    return;
  }
  assert(d == w[i]+dp(1+i, s-w[i], w));
  res.push_back(i);
  go(1+i, s-w[i], w, res);
}

vector<int> find_subset(int l, int u, vector<int> w) {
  memset(memo, -1, sizeof memo);
  ll s = dp(0, l, w);
  if (s >= l && s <= u) {
    vector<int> idx;
    go(0, l, w, idx);
    return idx;
  }
  return {};
}
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -