제출 #1031292

#제출 시각아이디문제언어결과실행 시간메모리
1031292TonylDetecting Molecules (IOI16_molecules)C++17
46 / 100
17 ms25436 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define REP(i,n) for (int i = 0; i < n; i++)

const int MAX_N = 10002;
const int MAX_L = 10002;

using b = bitset<MAX_L>;
b history[MAX_N];

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    history[0][0] = 1;
    int n = w.size();
    REP(i,n) {
        history[i+1] = history[i] | (history[i]<<w[i]);
    }

    // find sol
    int goal = -1;
    for (int i = l; i <= u; i++) {
        if (history[n][i]) goal = i;
    }
    
    if (goal == -1) return {};
    
    vi sel;
    int i = n;
    while (goal > 0) {
        while (history[i-1][goal]) i--;
        sel.push_back(i-1);
        goal -= w[i-1];
    }

    return sel;
}
#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...