제출 #759828

#제출 시각아이디문제언어결과실행 시간메모리
759828Doncho_BonbonchoKnapsack (NOI18_knapsack)C++14
73 / 100
1065 ms1492 KiB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
 
#define endl "\n"
 
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
 
#ifndef LOCAL
#define cerr if(false) cerr
#define endl "\n"
#endif
 
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template<typename T, typename B = decay<decltype(*begin(declval<T>()))>, typename enable_if<!is_same<T, string>::value>::type* = nullptr>
ostream& operator <<(ostream &os, const T &c) {
    bool f = false;
    os << "(";
    for(const auto &x : c) {
        if(f) os << ", "; f = true;
        os << x;
    }
    return os << ")";
}
 
 
#define out(x) #x << "=" << x << " "
struct debug {
    debug(const string &msg) { cerr << "LINE " << msg <<  ": "; }
    ~debug() { cerr << endl; }
 
    template<class T>
    debug& operator <<(const T x) {
        cerr << x;
        return *this;
    }
};
#define dbg debug(to_string(__LINE__))
 
typedef long long ll;
const ll mod = 1e9 + 7;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

ll dpNow[2001];
ll dpPrev[2001];
int v[100001];
int val[100001];
int num[100001];

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif
	
	int n, s;
	std::cin>>s>>n;
	for( int i=1 ; i<=n ; i++ ){
		std::cin>>val[i]>>v[i]>>num[i];
	}
	for( int i=1 ; i<=n ; i++ ){
		for( int j=0 ; j<=s ; j++ ){
			chkmax( dpNow[j], dpPrev[j] );
			if( j ) chkmax( dpNow[j], dpNow[j-1] );
			for( int k=1 ; k<=num[i] ; k++ ){
				cerr<<" ! "<<k<<" "<<v[i]*k<<endl;
				if( j- v[i]*k < 0 ) break;
				chkmax( dpNow[j], dpPrev[j-k*v[i]] + k*val[i] );
			}
			cerr<<i<<" "<<j<<" "<<" -> "<<dpNow[j]<<endl;
		}
		for( int j=0 ; j<=s ; j++ ){
			dpPrev[j] = dpNow[j];
		}
	}
			
	std::cout<<dpPrev[s]<<endl;
 
    return 0;
}

// To the OGs, I'm thankin' you now
// Was watchin' you when you was pavin' the ground
// I copied your cadence, I mirrored your style
// I studied the greats, I'm the greatest right now

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

knapsack.cpp: In function 'std::ostream& operator<<(std::ostream&, const T&)':
knapsack.cpp:24:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   24 |         if(f) os << ", "; f = true;
      |         ^~
knapsack.cpp:24:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   24 |         if(f) os << ", "; f = true;
      |                           ^
#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...