Submission #897949

#TimeUsernameProblemLanguageResultExecution timeMemory
897949duckindogDetecting Molecules (IOI16_molecules)C++14
0 / 100
1 ms2396 KiB
// from duckindog wth depression #include<bits/stdc++.h> using namespace std; //#define LOCAL #ifndef LOCAL #include "molecules.h" #endif // LOCAL struct T { int a, b; T(int aa, int bb) : a(aa), b(bb) {} }; const int N = 1e4 + 1; bool f[2][N]; pair<int, int> trace[N][N]; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); for (int i = 1; i < n; ++i) { int it = i + 1 & 1; f[1 - it][0] = f[1 - it][w[i - 1]] = 1; for (int j = 1; j <= u; ++j) { auto &ret = f[it][j]; if (f[1 - it][j]) { ret = 1; trace[i][j] = {i - 1, j}; } if (j - w[i] >= 0 && f[1 - it][j - w[i]]) { ret = 1; trace[i][j] = {i - 1, j - w[i]}; } } } vector<int> answer; int i = n - 1, j = 0; for (int x = l; x <= u; ++x) if (f[n - 1 & 1][x]) j = x; if (!j) return answer; while (j) { int pi, pj; tie(pi, pj) = trace[i][j]; if (j > pj) answer.push_back(i); i = pi; j = pj; } return answer; } #ifdef LOCAL int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } for (auto x : find_subset(10, 20, {15, 17, 16, 18})) cout << x << ' '; } #endif // LOCAL

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:24:16: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   24 |     int it = i + 1 & 1;
      |              ~~^~~
molecules.cpp:41:40: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   41 |   for (int x = l; x <= u; ++x) if (f[n - 1 & 1][x]) j = x;
      |                                      ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...