Submission #434577

#TimeUsernameProblemLanguageResultExecution timeMemory
434577KanaifuDetecting Molecules (IOI16_molecules)C++14
0 / 100
6 ms8140 KiB
#include <bits/stdc++.h> #include "molecules.h" //#include "grader.cpp" using namespace std; #define pb push_back #define x first #define y second vector<int> find_subset(int l, int u, vector<int> w) { vector <int> ret; pair<int,int> dp[1001][1001]; for (int i=0; i<=1000; i++) { dp[i][0] = {1, -1}; for (int j=1; j<=1000; j++) { dp[i][j] = {0, -1}; } } for (int i=0; i<w.size(); i++) { for (int j=u; j>=0; j--) { if (i>0) { dp[i][j] = dp[i-1][j]; } if (dp[i][j].x) { if (j+w[i]<=u) { dp[i][j+w[i]] = {1, i}; } } } } for (int j=l; j<=u; j++) { if (dp[w.size()-1][j].x) { int poz = w.size()-1; int weight = j; while (dp[poz][weight].y != -1) { ret.pb(dp[poz][weight].y); weight -= w[dp[poz][weight].y]; if (poz==0) { break; } poz = dp[poz-1][weight].y; } break; } } return ret; } /* 4 15 17 6 8 8 7 */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(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...