제출 #593502

#제출 시각아이디문제언어결과실행 시간메모리
593502wyhong3103Knapsack (NOI18_knapsack)C++14
17 / 100
2 ms1876 KiB
#include <bits/stdc++.h> #include <bits/stdc++.h> #define all(x) begin(x),end(x) #define fir first #define sec second #define sz(x) x.size() #define pb push_back using namespace std; using vi = vector<int>; using pi = pair<int,int>; using pdb = pair<double,double>; using ll = long long; using pll = pair<ll,ll>; const double EPS = (1e-7); void setio(string s){ freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } const int MXN = 1e5 + 5; const int MXS = 2001; //{val, k used} pair<int,int> dp[MXN][MXS]; struct Item{ int v, w, k; }; void solve(){ int n, s; cin >> s >> n; vector<Item> items(n); for(auto& i : items) cin >> i.v >> i.w >> i.k; for(int i{1}; i <= n; i++){ for(int j{1}; j <= s; j++){ //based on last dp[i][j].fir = max(dp[i-1][j].fir, dp[i][j].fir); if (j-items[i-1].w >= 0 && dp[i-1][j-items[i-1].w].fir + items[i-1].v > dp[i][j].fir){ dp[i][j].fir = dp[i-1][j-items[i-1].w].fir + items[i-1].v; dp[i][j].sec = 1; } //based on cur if (j-items[i-1].w >= 0 && dp[i][j-items[i-1].w].fir + items[i-1].v > dp[i][j].fir && dp[i][j-items[i-1].w].sec + 1 <= items[i-1].k){ dp[i][j].fir = dp[i][j-items[i-1].w].fir + items[i-1].v; dp[i][j].sec = dp[i][j-items[i-1].w].sec + 1; } } } cout << dp[n][s].fir; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while(t--){ solve(); } return 0; }

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

knapsack.cpp: In function 'void setio(std::string)':
knapsack.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  freopen((s + ".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  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...