Submission #1097910

#TimeUsernameProblemLanguageResultExecution timeMemory
1097910dzhoz0Detecting Molecules (IOI16_molecules)C++17
0 / 100
0 ms348 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> sub1(int l, int u, vector<int> w) { int n = w.size(); int cur = 0; vector<int> res; for(int i = 0; i < n; i++) { cur += w[i]; res.push_back(i); if(cur >= l && cur <= u) { return res; } } return vector<int>(0); } vector<int> sub123(int l, int u, vector<int> w) { int n = w.size(); vector<pair<bool, int>> dp(u + 5, {false, -1}); dp[0] = {true, -1}; for(int i = 0; i < n; i++) { for(int x = u; x >= w[i]; x--) { if(dp[x - w[i]].first == true) { if(x + w[i] <= u) { dp[x + w[i]] = {true, i}; } dp[x] = {true, i}; } } } // for(int x = 0; x <= u; x++) { // cout << x << ' ' << dp[x].first << '\n'; // } for(int val = l; val <= u; val++) { if(dp[val].first == true) { int x = val; // cout << x << ' ' << dp[x].second << '\n'; vector<int> res; int id = dp[x].second; while(id != -1) { res.push_back(id); // cout << id << '\n'; x -= w[id]; id = dp[x].second; } // cout << res.size() << '\n'; return res; } } return vector<int>(0); } vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); // sort(w.begin(), w.end()); int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end()); if(u <= 1000) return sub123(l, u, w); return vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:65:9: warning: unused variable 'n' [-Wunused-variable]
   65 |     int n = w.size();
      |         ^
molecules.cpp:67:9: warning: unused variable 'mx' [-Wunused-variable]
   67 |     int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end());
      |         ^~
molecules.cpp:67:48: warning: unused variable 'mi' [-Wunused-variable]
   67 |     int mx = *max_element(w.begin(), w.end()), mi = *min_element(w.begin(), w.end());
      |                                                ^~
#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...