Submission #1219448

#TimeUsernameProblemLanguageResultExecution timeMemory
1219448AMel0nDetecting Molecules (IOI16_molecules)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first 
#define S second

#include "molecules.h"

vector<int> find_subset(int l, int u, vector<int> W) {
    // bitset<32> dp;
    vector<pair<bool, int>> dp(u+1);
    dp[0].F = 1;
    vector<int> res;
    // bitset<200000> res;
    // int backtrack = 0;
    pair<bool,int> yes = {0,0};

    FOR(i, W.size()) {
        for(int w = u; w >= 0; w--) {
            if (w != 0 && w-W[i] >= 0) {
                if (dp[w-W[i]].F) {
                    dp[w] = {(dp[w-W[i]].F == 1), i};
                }
            }
            // cout << i << ' ' << w<< ' '<<dp[w] << ' ' << W[i] << endl;
            if (l <= w && w <= u && dp[w].F)  {
                yes = {1, w};
                break;
            }
        }
        // if (yes) break;
    }
    if (!yes.F) return res;

    while(yes.S != 0) {
        // cout << yes.S << ' '<<dp[yes.S].S << ' ' << W[dp[yes.S].S] <<endl;
        res.push_back(dp[yes.S].S);
        yes.S = yes.S - W[dp[yes.S].S];
    }
    // while(backtrack != 0) {
    //     FOR(i,W.size()) {
    //         // cout << backtrack << ' ' << i << ' ' << W[i] << ' '<< dp[backtrack-W[i]] << endl;
    //         if (backtrack-W[i] >= 0 && dp[backtrack-W[i]] == 1 && find(all(res), i) == res.end()) {
    //             res.push_back(i);
    //             backtrack = backtrack-W[i];
    //             break;
    //         }
    //     }
    // }
    return res;
}

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...