이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pll pair<long long, long long>
#define pii pair<int, int>
#include "molecules.h"
using namespace std;
int n;
vector <int> case1234(int l, int u, vector <int> w) {
vector <bool> dp[2];
vector <int> take;
dp[0].assign(u + 1, false);
dp[1].assign(u + 1, false);
take.assign(u + 1, -1);
dp[1][0] = true;
for (int i = 0; i < w.size(); i++) {
int md = i % 2;
for (int j = w[i]; j <= u; j++) {
if (dp[1 - md][j])
continue;
if (dp[1 - md][j - w[i]]) {
dp[md][j] = true;
take[j] = i;
}
}
for (int j = 0; j <= u; j++)
dp[md][j] = (dp[md][j] | dp[1 - md][j]);
}
vector <int> ans = {};
for (int i = l; i <= u; i++)
if (dp[w.size() - 1][i]) {
int cur = i;
while (cur != 0) {
ans.pb(take[cur]);
cur -= w[take[cur]];
}
break;
}
sort(ans.begin(), ans.end());
return ans;
}
vector <int> find_subset(int l, int u, vector <int> w) {
n = w.size();
int maxw = 0;
for (int to : w)
maxw = max(maxw, to);
if (n <= 10000 && maxw <= 10000 && u <= 10000)
return case1234(l, u, w);
return {};
}
//int main() {
// freopen("input.txt", "r", stdin);
// int n, l, u;
// assert(3 == scanf("%d %d %d", &n, &l, &u));
// std::vector<int> w(n);
// for (int i = 0; i < n; i++)
// assert(1 == scanf("%d", &w[i]));
// std::vector<int> result = find_subset(l, u, w);
//
//
// printf("%d\n", (int)result.size());
// for (int i = 0; i < (int)result.size(); i++)
// printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
//}
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> case1234(int, int, std::vector<int>)':
molecules.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < w.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |