Submission #1138164

#TimeUsernameProblemLanguageResultExecution timeMemory
1138164AliyyiakbarDetecting Molecules (IOI16_molecules)C++20
31 / 100
1093 ms580 KiB
#include "molecules.h"
#include "bits/stdc++.h"
using namespace std;

const int sz = 1e6 + 9;
const int N = 10001;

vector<int> find_subset(int l, int r, vector<int> w)
{
    bitset<sz> dp;
    dp[0] = 1;
    int n = w.size();
    for (int i = 0; i < n; ++i)
    {
        for (int j = 1e6; j >= 0; --j)
        {
            if (j + w[i] <= 1e6 && dp[j])
            {
                dp[j + w[i]] = 1;
            }
        }
    }
    vector<int> ans;
    for(int i = l; i <= r; ++i)
    {
        if (dp[i])
        {
            bitset<N> take;
            for (int j = 0; j < n; ++j)
            {
                if (i - w[j] >= 0 && dp[i - w[j]] && take[j] == 0)
                {
                    ans.push_back(j);
                    take[j] = 1;
                    i -= w[j];
                    j = 0;
                }
            }
            return ans;
        }
    }
    return {};
}

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...