이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
//#define int long long
constexpr int sz = 1e5 + 5;
constexpr long long inf = (long long)1E18 + 7;
int n, s;
struct ou{
int v, w, k;
} a[sz];
long long dp[2005];
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> s >> n;
for(register int i = 1; i <= n; ++i){
cin >> a[i].v >> a[i].w >> a[i].k;
a[i].k = min(a[i].k, s / a[i].w);
}
for(register int i = 1; i <= 2001; ++i){
dp[i] = -inf;
}
for(register int i = 1; i <= n; ++i){
for(register int ki = 1; ki <= a[i].k; ++ki)
for(register int j = s; j >= a[i].w; --j){
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
long long ans = *max_element(dp, dp+s+1);
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:25:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
25 | for(register int i = 1; i <= n; ++i){
| ^
knapsack.cpp:30:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
30 | for(register int i = 1; i <= 2001; ++i){
| ^
knapsack.cpp:34:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
34 | for(register int i = 1; i <= n; ++i){
| ^
knapsack.cpp:35:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
35 | for(register int ki = 1; ki <= a[i].k; ++ki)
| ^~
knapsack.cpp:36:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
36 | for(register int j = s; j >= a[i].w; --j){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |