Submission #416884

#TimeUsernameProblemLanguageResultExecution timeMemory
416884snasibov05Detecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include "molecules.h"
#include <algorithm>

using namespace std;

#define pb push_back

bool dp[2][10000][500000];

void knapsack(vector<int>& w, int sum){
    int n = w.size();

    if (w[0] <= sum) dp[1][0][w[0]] = true;
    dp[0][0][0] = true;

    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j <= sum; ++j) {
            if (dp[0][i][j] || dp[1][i][j]){
                dp[0][i+1][j] = true;
                if (j + w[i+1] <= sum) dp[1][i+1][j + w[i+1]] = true;
            }
        }
    }
}

vector<int> find_subset(int l, int u, vector<int> w) {

    int n = w.size();
    knapsack(w, u);

    int res = -1;
    for (int i = l; i <= u; ++i) {
        if (dp[1][n-1][i] || dp[0][n-1][i]) {
            res = i;
            break;
        }
    }

    vector<int> ans;
    if (res == -1) return ans;
    for (int i = n-1; i >= 0; --i){
        if (dp[1][i][res]){
            ans.pb(i);
            res -= w[i];
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;

}

Compilation message (stderr)

/usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x1e): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(eh_alloc.o): in function `(anonymous namespace)::pool::free(void*) [clone .constprop.0]':
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0x18): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0x2c): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0x53): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0xb7): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0xc3): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool4freeEPv.constprop.0+0x116): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
/usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(eh_alloc.o): in function `(anonymous namespace)::pool::allocate(unsigned long) [clone .constprop.0]':
(.text._ZN12_GLOBAL__N_14pool8allocateEm.constprop.0+0x19): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool8allocateEm.constprop.0+0x3b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN12_GLOBAL__N_114emergency_poolE'
(.text._ZN12_GLOBAL__N_14pool8allocateEm.constprop.0+0x53): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status