Submission #588885

#TimeUsernameProblemLanguageResultExecution timeMemory
588885mahra_IOIDetecting Molecules (IOI16_molecules)C++17
31 / 100
162 ms65536 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
     
     
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    vector <int> ret;
     
    int n = w.size();
     
    vector <pii> W(n);
    for(int i = 0; i < n; ++i) {
        W[i] = {w[i], i};
    }
        
    const int MAXN = 5e5+1;
    vector <bitset <MAXN>> dp(n+1);
    dp[0][0] = true;
     
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j < MAXN; ++j) {
            dp[i][j] = dp[i][j] || dp[i-1][j];
            if (W[i-1].first <= j) dp[i][j] = dp[i][j] || dp[i-1][j-W[i-1].first];
        }
    }
     
    for(int i = l; i <= u; ++i) {
        int target = i;
        if (dp[n][target] == false) continue;
        vector <int> tmp;
        for(int j = n; j > 0; --j) {
            if (dp[j-1][target]) continue;
                tmp.push_back(W[j-1].second);
                target -= W[j-1].first;
            }
            if (target == 0) {
                ret = tmp;
                break;
            }
        }
    return ret;
}
#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...