제출 #1008408

#제출 시각아이디문제언어결과실행 시간메모리
1008408cpdreamerKnapsack (NOI18_knapsack)C++14
37 / 100
2 ms604 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; const int inf=1e8; typedef long long ll; #define LLM LONG_LONG_MAX #define pb push_back #define F first #define P pair #define all(v) v.begin(),v.end() #define V vector #define S second const long long MOD = 998244353; // 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); } struct product{ int value; int weight; int copies; }; bool sorted(product a,product b){ return a.value>b.value; } void solve() { int n,W; cin>>W>>n; V<V<int>>weights(W+1); product A[n]; for(int i=0;i<n;i++){ cin>>A[i].value>>A[i].weight>>A[i].copies; } sort(A,A+n,sorted); for(int i=0;i<n;i++){ int a=A[i].value,b=A[i].weight,c=A[i].copies; int limit=W/b; for(int j=0;j<min(limit-(int)weights[b].size(),c);j++){ weights[b].pb(a); } } ll dp[W+1]; memset(dp,0LL,sizeof(dp)); for(int i=1;i<=W;i++){ for(auto u:weights[i]){ for(int j=W;j>=i;j--){ dp[j]=max(dp[j],dp[j-i]+u); } } } 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...