제출 #556274

#제출 시각아이디문제언어결과실행 시간메모리
556274Talha_TakiDetecting Molecules (IOI16_molecules)C++17
46 / 100
400 ms13268 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 = 1e4;
    vector <vector <bool>> dp(n+1, vector <bool> (MAXN+1, false));
    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...