Submission #1000241

#TimeUsernameProblemLanguageResultExecution timeMemory
1000241overwatch9Detecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms604 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, std::vector<int> w) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n = w.size(); vector <int> dp(u+1, 1e9); dp[0] = -1; set <int> filled, not_filled; filled.insert(0); for (int i = 1; i <= u; i++) not_filled.insert(i); for (int i = 0; i < n; i++) { if (not_filled.size() < filled.size()) { vector <int> to_shift; for (auto j : not_filled) { if (j >= w[i] && dp[j - w[i]] != 1e9) { to_shift.push_back(j); dp[j] = i; } } for (auto j : to_shift) { not_filled.erase(j); filled.insert(j); } } else { vector <int> to_shift; for (auto j : filled) { if (j + w[i] <= u && dp[j + w[i]] == 1e9) { to_shift.push_back(j + w[i]); dp[j + w[i]] = i; } } for (auto j : to_shift) { not_filled.erase(j); filled.insert(j); } } } int st = -1; vector <int> ans; for (int i = l; i <= u; i++) { if (dp[i] != 1e9) { st = i; break; } } if (st == -1) return ans; while (st > 0) { int nxt = dp[st]; ans.push_back(nxt); st = st - w[nxt]; } return ans; }
#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...