제출 #501372

#제출 시각아이디문제언어결과실행 시간메모리
501372zhangjishenKnapsack (NOI18_knapsack)C++98
37 / 100
2 ms460 KiB
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;}
typedef long long ll;

const int MAXN = 3e6 + 10, MAXS = 2e3 + 10;

int s, n;
ll v[MAXN], w[MAXN], f[MAXS];

int main(){
	// input
	scanf("%d %d", &s, &n);
	int a, b, c;
	int t = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d %d %d", &a, &b, &c);
		for(int p = 1; p <= c; p *= 2){
			t++; c -= p;
			v[t] = p * a;
			w[t] = p * b;
		}
		if(c){
			t++; 
			v[t] = c * a;
			w[t] = c * b;
		}
	}
	n = t;
	// dp
	memset(f, 0, sizeof(f));
	for(int i = 1; i <= n; i++)
		for(int j = s; j >= 1; j--)
			if(w[i] <= j)
				chkmax(f[j], f[j - w[i]] + v[i]);
	printf("%lld\n", f[s]);
}

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d %d", &s, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d %d %d", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...