답안 #1104526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104526 2024-10-24T02:08:32 Z ngano_upat_na Detecting Molecules (IOI16_molecules) C++17
컴파일 오류
0 ms 0 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include "bits/stdc++.h"
#include "molecules.h"
using namespace std;
using ll = long long;

vector<int> find_subset(int l, int u, vector<int> w) {
    srand(time(0));

    int n = (int)w.size();
    ll sum = 0;
    for (int i=0; i<n; i++) {
        sum += (ll)w[i];
    }
    if (sum == u) {
        vector<int> res;
        for (int i=0; i<n; i++) {
            res.push_back(i);
        }
        return res;
    }
    if (sum < l) {
        return {};
    }

    for (int i=0; i<2000; i++) {
        set<int> s;
        for (int j=0; j<n; j++) {
            int r = rand()%n;
            s.insert(r);
        }
        sum = 0;
        for (auto &e:s) {
            sum += w[e];
        }
        if (l <= sum && sum <= r) {
            vector<int> res;
            for (auto &e:s) {
                res.push_back(e);
            }
            return res;
        }
    }
    return {};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:36:32: error: 'r' was not declared in this scope
   36 |         if (l <= sum && sum <= r) {
      |                                ^