이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define task "a"
#define etr "\n"
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define bg begin
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define lwb lower_bound
#define upb upper_bound
#define range(x, l, r) x+l, x+1+r
#define all(x) (x).bg(), (x).end()
#define compact(x) x.resize(unique(all(x)) - (x).bg())
#define sq(x) ((x)*(x))
auto start = chrono::high_resolution_clock::now();
void start_timer()
{
start = chrono::high_resolution_clock::now();
}
ld elapsed()
{
auto current = chrono::high_resolution_clock::now();
ld duration = chrono::duration_cast<chrono::nanoseconds>(current - start).count();
return duration / 1e9;
}
void freop()
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
template<typename U, typename V> istream& operator >> (istream& in, pair<U, V>& p)
{
in >> p.fi >> p.se;
return in;
}
template<typename U, typename V> ostream& operator << (ostream& out, pair<U, V> p)
{
out << p.fi << ' ' << p.se;
return out;
}
const int N=2e5, M=1e5, mod=1e9+7;
typedef array<ll, 3> Item;
int n, s;
ll dp[N+5];
void process()
{
cin >> s >> n;
vector<Item> a;
for (int i=1; i<=n; i++)
{
ll v, w, k;
cin >> v >> w >> k;
for (int j=1; j<=k; j<<=1)
{
if (w * j > s) break;
a.pb({v*j, w*j, j});
k -= j;
}
if (w * k <= s) a.pb({v*k, w*k, k});
}
n = a.size();
for (int i=0; i<n; i++)
{
for (int j=s; j>=a[i][1]; j--) dp[j] = max(dp[j], dp[j - a[i][1]] + a[i][0]);
}
ll res = 0;
for (int i=0; i<=s; i++) res = max(res, dp[i]);
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1; //cin >> t;
while (t--) process();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'void freop()':
knapsack.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:42:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |