제출 #571040

#제출 시각아이디문제언어결과실행 시간메모리
571040webDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms212 KiB
#include <iostream> #include "molecules.h" #include <algorithm> using namespace std; vector<vector<pair<int, int>>> dp; void knapsack(vector<int>& weights, int u) { for(int i = 0; i<weights.size(); ++i) { for(int weight = 0; weight <= u; ++weight) { if(weight < weights[i]) { dp[i+1][weight] = dp[i][weight]; } else { if(dp[i][weight].first >= dp[i][weight - weights[i]].first+ weights[i]) { dp[i+1][weight] = dp[i][weight]; } else { dp[i+1][weight] = {dp[i][weight-weights[i]].first + weights[i], i}; } } } } } std::vector<int> find_subset(int l, int u, std::vector<int> w) { dp = vector<vector<pair<int,int>>>(w.size()+1, vector<pair<int,int>>(u+1, {0, -1})); knapsack(w, u); //cout<<"begin pair: "; pair<int,int> currP = dp[w.size()][u]; //cout<<currP.first<<" "<<currP.second<<endl; if(currP.first < l) return vector<int>(0); vector<int> retVal; int currWeight = currP.first; while(currP.second != -1) { retVal.push_back(currP.second+1); currP = dp[currP.second][currWeight-w[currP.second]]; currWeight-=w[currP.second]; // cout<<"new pair: " <<currP.first<<" "<<currP.second<<endl; } return retVal; }

컴파일 시 표준 에러 (stderr) 메시지

molecules.cpp: In function 'void knapsack(std::vector<int>&, int)':
molecules.cpp:9:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i = 0; i<weights.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...