제출 #992967

#제출 시각아이디문제언어결과실행 시간메모리
992967cpdreamerKnapsack (NOI18_knapsack)C++17
73 / 100
1090 ms2904 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <utility> using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int max_n=INT_MAX; typedef long long ll; #define LLM LONG_LONG_MAX #define pb push_back #define F first #define L length() #define all(v) v.begin(),v.end() #define P pair #define V vector #define S second const long long MOD = 1000000007; // 1e9 + 7 void file(){ freopen("input.txt.txt","r",stdin); freopen("output.txt.txt","w",stdout); } void setio(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } bool is_sorted(int A[],int n){ for(int i=0;i<n-1;i++){ if(A[i]>A[i+1]) return false; } return true; } void solve() { int n,W; cin>>W>>n; int k[n],w[n],v[n]; ll dp[W+1]; bool made[W+1]; memset(dp,-1,sizeof(dp)); memset(made,0,sizeof(made)); for(int i=0;i<n;i++){ cin>>v[i]>>w[i]>>k[i]; } dp[0]=0; made[0]=true; for(int i=0;i<n;i++){ for(int j=W;j>=w[i];j--){ for(int g=1;g<=k[i];g++){ if(g*w[i]>j) break; if(made[j-g*w[i]]){ dp[j]=max(dp[j],dp[j-g*w[i]]+v[i]*g); made[j]=true; } } } } cout<<*max_element(dp,dp+W+1)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //file(); solve(); return 0; }

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

knapsack.cpp: In function 'void file()':
knapsack.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'void setio(std::string)':
knapsack.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((s + ".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...