Submission #295902

#TimeUsernameProblemLanguageResultExecution timeMemory
295902RealSuperman1Detecting Molecules (IOI16_molecules)C++14
46 / 100
528 ms692 KiB
#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> 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]); //}

Compilation message (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 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...