이 제출은 이전 버전의 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 = {};
int md = 1 - n % 2;
for (int i = l; i <= u; i++)
if (dp[md][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> case56(int l, int u, vector <int> w) {
ll sm = 0;
vector <pair<ll, int> > x;
set <int> ans = {};
for (int i = 0; i < w.size(); i++)
x.pb({w[i] * 1ll, i});
sort(x.begin(), x.end());
bool flag = false;
int cur = 0;
for (int i = 0; i < x.size(); i++) {
if (x[i].fi + sm <= u) {
sm += x[i].fi;
ans.insert(x[i].se);
} else {
sm += x[i].fi - x[cur].fi;
ans.erase(x[cur].se);
ans.insert(x[i].se);
cur++;
}
if (l <= sm) {
flag = true;
break;
}
}
if (!flag)
return {};
vector <int> anss = {};
for (set <int>::iterator it = ans.begin(); it != ans.end(); it++)
anss.pb(*it);
sort(anss.begin(), anss.end());
return anss;
}
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 case56(l, u, w);
}
컴파일 시 표준 에러 (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++) {
| ~~^~~~~~~~~~
molecules.cpp: In function 'std::vector<int> case56(int, int, std::vector<int>)':
molecules.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < w.size(); i++)
| ~~^~~~~~~~~~
molecules.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i = 0; i < x.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... |