Submission #305511

#TimeUsernameProblemLanguageResultExecution timeMemory
305511tengiz05Detecting Molecules (IOI16_molecules)C++17
31 / 100
1096 ms13184 KiB
#include "molecules.h" //#include "grader.cpp" #include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); vector<vector<bool>> dp(10001, vector<bool> (n)); vector<bool> able(10001); vector<int> ans; int sum = 0; int mn = (1<<31)-1; //cout << mn << ' ' ; for(auto x : w)sum += x, mn = min(mn, x); if(sum < l)return ans; /* queue<pair<int, vector<bool>> q; queue.push({0, dp[0]}); while(!q.empty()){ auto tt = q.top(); int t = q.first; if(t > u)continue; if(t >= l && t <= u){ } }*/ for(int j=0;j<n;j++){ if(w[j] <= 10000 && !able[w[j]]){ able[w[j]] = true; dp[w[j]][j] = true; } } for(int i=mn;i<10000;i++){ if(!able[i])continue; if(i >= l){ if(i <= u){ for(int j=0;j<n;j++){ if(dp[i][j])ans.push_back(j); } } break; } for(int j=0;j<n;j++){ if(i+w[j] <= 10000 && !dp[i][j]){ able[i+w[j]] = true; dp[i+w[j]] = dp[i]; dp[i+w[j]][j] = true; } } } return ans; } /* 4 15 17 6 8 8 7 4 14 15 5 5 6 6 4 10 20 15 17 16 18 */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:18: warning: integer overflow in expression of type 'int' results in '2147483647' [-Woverflow]
   13 |  int mn = (1<<31)-1;
      |           ~~~~~~~^~
#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...