Submission #546881

#TimeUsernameProblemLanguageResultExecution timeMemory
546881fvogel499Detecting Molecules (IOI16_molecules)C++17
0 / 100
2 ms2516 KiB
/*
 * File created on 04/07/2022 at 22:12:14.
 * Link to problem: 
 * Description: 
 * Time complexity: O()
 * Space complexity: O()
 * Status: ---
 * Copyright: Ⓒ 2022 Francois Vogel
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

#define pii pair<int, int>
#define f first
#define s second

#define vi vector<int>
#define all(x) x.begin(), x.end()
#define size(x) (int)((x).size())
#define pb push_back
#define ins insert
#define cls clear

// #define int ll
#define ll long long
#define ld long double

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int siz = 5e5+40;

vi find_subset(int start, int end, vi b) {
    bitset<siz> knapsack;
    knapsack.reset();
    knapsack.flip(0);
    int ori [siz];
    for (int i = 0; i < siz; i++) ori[i] = -1;
    bitset<siz> pre, loc;
    bool found = true;
    for (int i = 0; i < size(b); i++) {
        pre = knapsack<<b[i];
        loc = (pre^knapsack)&pre;
        knapsack |= pre;
        while (loc.any()) {
            int pos = loc._Find_first();
            assert(ori[pos] == -1);
            ori[pos] = i;
            if (start <= pos && pos <= end) {
                found = true;
                break;
            }
            loc.flip(pos);
        }
        if (found) break;
    }
    vi res;
    for (int i = start; i <= end; i++) if (ori[i] != -1) {
        int x = i;
        while (x > 0) {
            res.pb(ori[x]);
            x -= b[ori[x]];
        }
        break;
    }
    return res;
}

// signed main() {
//     cin.tie(0);
//     ios_base::sync_with_stdio(0);

//     int n, l, u;
//     cin >> n >> l >> u;
//     vi b(n);
//     for (int i = 0; i < n; i++) cin >> b[i];
//     vi res = find_subset(l, u, b);
//     for (int i : res) cout << i << ' ';

//     cout.flush();
//     int d = 0;
//     d++;
// }
#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...