Submission #240232

#TimeUsernameProblemLanguageResultExecution timeMemory
240232Dremix10Detecting Molecules (IOI16_molecules)C++17
31 / 100
145 ms65540 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define F first #define S second //#define endl '\n' #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define maxp 22 #define EPS (ld)(1e-18) #define mod (int)(1e9+7) #define N (int)(1e5+1) bool dp[10001][10001]; vector<int> find_subset(int l, int r, vector<int> arr) { int n=arr.size(); int i,j; dp[0][0]=true; for(i=1;i<=n;i++) for(j=0;j<=10001;j++){ dp[i][j]|=dp[i-1][j]; if(j>=arr[i-1]) dp[i][j]|=dp[i-1][j-arr[i-1]]; } int k; for(k=l;k<=r;k++) if(dp[n][k]){ //cout<<n<<" "<<k<<endl; vector<int> ans; int num=k; int row=n; while(num>0){ for(i=row;i>0;i--) if(num>=arr[i-1]) if(dp[i-1][num-arr[i-1]]){ row=i-1; num-=arr[i-1]; ans.push_back(i-1); break; } } return ans; } return vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:27:17: warning: iteration 10001 invokes undefined behavior [-Waggressive-loop-optimizations]
         dp[i][j]|=dp[i-1][j];
         ~~~~~~~~^~~~~~~~~~~~
molecules.cpp:26:14: note: within this loop
     for(j=0;j<=10001;j++){
             ~^~~~~~~
#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...