Submission #445779

#TimeUsernameProblemLanguageResultExecution timeMemory
445779PulgsterKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms332 KiB
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; typedef long long ll; using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { // #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } // sim dor(const c&) { ris; } }; #ifdef ASJKD } #endif #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define read(x) for(auto &i : (x)){cin>>i;} #define all(x) begin(x), end(x) #define pb push_back #define pll pair<ll,ll> #define pii pair<int,int> // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> int mod = 1e9+7; int INF = 1e9+1e8; ll INF64 = 1e18; ll binpow(ll a, ll b, ll mod){ ll res = 1; while(b > 0){ if(b % 2){ res = res * a % mod; } a = a * a % mod; b >>= 1; } return res; } void mxself(int &a, int b){ a = max(a, b); } void rpii(pii &a){ cin>>a.first>>a.second; } void mnself(int &a,int b){ a = min(a, b); } void mult(ll &a, ll b){ a = a * b % mod; } void add(ll &a, ll b){ a = (a + b); while(a >= mod) a -= mod; } void setIO(string s){ freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } void test_case(int test){ int s, n; cin>>s>>n; vector<int> v(n); vector<int> w(n); vector<int> q(n); for(int i=0;i<n;i++){ cin>>v[i]>>w[i]>>q[i]; } vector<pair<ll,int>> dp(s+1, make_pair(0, 0)); // v, used; for(int i=0;i<n;i++){ for(int j=0;j<=s;j++){ dp[j].second = 0; } for(int j=0;j<=s;j++){ if(w[i] + j > s) break; if(1 + dp[j].second <= q[i]){ if(dp[j].first + v[i] >= dp[j+w[i]].first){ if(dp[j].first + v[i] == dp[j+w[i]].first){ if(1 + dp[j].second < dp[j+w[i]].second){ dp[j+w[i]].second = 1 + dp[j].second; } } else{ dp[j+w[i]].first = dp[j].first + v[i]; dp[j+w[i]].second = dp[j].second+1; } } } } } ll ans = 0; for(int i=s;i>=0;i--){ ans = max(ans, dp[i].first); } cout<<ans<<'\n'; } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int t=1; // setIO("feast"); // cin>>t; for(int test=1;test<=t;test++){ test_case(test); } return 0; }

Compilation message (stderr)

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