이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
using namespace std;
#include <bits/stdc++.h>
#define MAX_N 200001
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
int L{};
int U{};
int n{};
vi mols;
vi addMolecule(const int &i, const int &w, const unordered_set<int> &used)
{
int nw = w + mols[i];
if (nw > U)
{
return addMolecule(i + 1, w, used);
}
if (nw >= L)
{
vi solution(ALL(used));
return solution;
}
auto dontAdd = addMolecule(i + 1, w, used);
if (dontAdd.size() > 0)
return dontAdd;
unordered_set<int> newUsed(used);
newUsed.insert(i);
auto add = addMolecule(i + 1, nw, newUsed);
if (add.size() > 0)
return add;
return {};
}
vi find_subset(int l, int u, vi w)
{
n = w.size();
bool allSame = true;
for (int i = 1; i < n; i++)
{
if (w[i] != w[i - 1])
{
allSame = false;
break;
}
}
if (allSame)
{
int s = 0;
int i = 0;
vi res;
for (int i = 0; i < n; i++)
{
s += w[0];
res.push_back(i);
if (s > u)
break;
if (s >= l)
return res;
}
return {};
}
L = l;
U = u;
mols = w;
return addMolecule(0, 0, {});
}
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:56:13: warning: unused variable 'i' [-Wunused-variable]
56 | int i = 0;
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |