This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a,val) memset(a, val, sizeof a)
#define PB push_back
#define endl '\n'
inline int myrand(int l, int r) {
int ret = rand(); ret <<= 15; ret ^= rand();
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
return os<<"(" <<p.first<<", "<<p.second<<")"; }
typedef pair<int, int> ii;
template<typename T> using min_pq =
priority_queue<T, vector<T>, greater<T> >;
//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};
const int maxn = 10005;
vector<vector<bool>> dp;
int a[maxn], l, n, u;
int get(int i, int v) {
if(l <= v and v <= u) return 1;
if(v > u or i == n) return 0;
return dp[i][v];
}
void fill(int i, int v, vector<int> &ret) {
if(l <= v and v <= u) {
return;
}
assert(i < n);
if(get(i + 1, v)) {
fill(i + 1, v, ret);
} else {
ret.push_back(i);
fill(i + 1, v + a[i], ret);
}
}
vector<int> find_subset(int L, int U, vector<int> w) {
dp.assign(maxn, vector<bool>(maxn));
n = w.size(), l = L, u = U;
for(int i=0; i<n; i++)
a[i] = w[i];
for(int i = n; i >= 0; i--) {
bool r1, r2;
for(int v = 0; v <= u; v++) {
if(l <= v and v <= u) dp[i][v] = 1;
else if(i == n) dp[i][v] = 0;
else {
r1 = dp[i + 1][v];
r2 = v + a[i] > u ? 0 : dp[i + 1][v + a[i]];
dp[i][v] = r1 | r2;
}
}
}
if(dp[0][0]) {
vector<int> ret;
fill(0, 0, ret);
return ret;
}
else {
return vector<int>();
}
}
Compilation message (stderr)
molecules.cpp: In function 'int myrand(int, int)':
molecules.cpp:17:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~
molecules.cpp:17:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
^~~
# | 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... |