제출 #585056

#제출 시각아이디문제언어결과실행 시간메모리
585056maskrioKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms468 KiB
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <iomanip> using namespace std; #define ll long long #define deb(x) cout << #x << " = " << x << endl; #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define mp make_pair #define fo(i, j) for(i=0;i<j;i++) #define Fo(i, k, n) for(i=k;k<n?i<n:i>n;k<n?i++:i--) #define MOD ((int)1e9+7) #define imax INT_MAX #define imin INT_MIN #define PI 3.1415926535897932384626433832795 #define tr(it, x) for(auto it = x.begin(); it != x.end(); it++) #define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+) #define sortall(x) sort(all(x)) #define here cout << "~~~~~~~~~~~~~~YES~~~~~~~~~~~~~~\n"; fflush(stdout); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<string> VS; typedef vector<PII> VII; typedef vector<VI> VVI; typedef map<int,int> MPII; template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; } void WVI(VI ar){ int i; fo(i, ar.size()){ cout << ar[i] << " "; }cout << endl; } void setIO(string name = ""){ ios_base::sync_with_stdio(0); cin.tie(0); if(name.size()>0){ freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int mxN = 1e5+5; const int INF = 1e9+50; //************************************************************** int s,n; int v[mxN], w[mxN], k[mxN]; VVI dp; int f(int weight, int x){ if(dp[weight][x] != -1) return dp[weight][x]; if(weight==0) dp[0][x] = 0; else{ dp[weight][x] = f(weight-1, x); if(weight-w[x]>=0){ if(k[x]>0){ k[x]--; dp[weight][x] = max(dp[weight][x], f(weight-w[x], x)+v[x]); k[x]++; } }if(x>1){ if(weight-w[x-1]>=0){ if(k[x-1]>0){ k[x-1]--; dp[weight][x] = max(dp[weight][x], f(weight-w[x-1], x-1)+v[x-1]); } }} } return dp[weight][x]; } void solve(){ cin >> s >> n; dp.resize(s+5, VI(n+5, -1)); for(int i=1;i<=n;i++){ cin >> v[i] >> w[i] >> k[i]; } cout << f(s,n) <<endl; } int main(){ string name = ""; setIO(name); int test_cases = 1; //cin >> test_cases; while(test_cases--) { solve(); } return 0; }

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

knapsack.cpp: In function 'void WVI(VI)':
knapsack.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 | #define fo(i, j) for(i=0;i<j;i++)
......
   61 |     fo(i, ar.size()){
      |        ~~~~~~~~~~~~        
knapsack.cpp:61:5: note: in expansion of macro 'fo'
   61 |     fo(i, ar.size()){
      |     ^~
knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...