이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* -> Written by <-
-----------
|K_A_Z_A_M_A|
|___________|
| ___ |
| (^_^) |
| /( | )\ |
|____|_|____|
H O A N G
*/
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using db = long double;
//using int = long long
#define Task "cowjog"
#define F first
#define S second
#define eb emplace_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define bit(x, i) (((x) >> (i)) & 1)
#define endl '\n'
#define fr(i,a,b) for (int i = (int)(a); i <= (int)(b); ++ i)
#define FR(i,a,b) for (int i = (int)(a); i < (int)(b); ++ i)
#define frr(i,a,b) for (int i = (int)(a); i >= (int)(b); -- i)
#define fre(i, a) for (auto &i : a)
#define debug(x) cerr << #x << " is " << x << "\n";
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
const int MOD = 1e9 + 7;
const ll MM = (ll)MOD * MOD;
const int base = 331;
const int B = 32;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dy8[] = {1, -1, 0, 1, -1, 0, 1, -1};
const int dx4[] = {0, 0, 1, -1};
const int dy4[] = {1, -1, 0, 0};
int s, n;
vector <pair <int, int>> e[2005];
pair <int, int> a[100005];
int dp[2005];
void solve(int test_case) {
cin >> s >> n;
fr(i, 1, n) {
int v, w, k;
cin >> v >> w >> k;
e[w].eb(v, k);
}
n = 0;
fr(w, 1, s) {
sort(all(e[w]), greater <pair <int, int>> ());
int bef = n;
fre(p, e[w]) {
fr(j, 1, p.S) {
if ((n+1-bef) * w > s)
break;
a[++n] = {w, p.F};
}
}
}
fr(i, 1, s)
dp[i] = - 2e9 - 7;
fr(i, 1, n) {
frr(j, s, 0)
if (j + a[i].F <= s)
dp[j+a[i].F] = max(dp[j+a[i].F], dp[j] + a[i].S);
}
int res = - 2e9 - 7;
fr(i, 0, s)
res = max(res, dp[i]);
cout << res;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
freopen(".ou", "w", stderr);
}
else if (fopen(Task".in", "r")) {
freopen(Task".in", "r", stdin);
freopen(Task".out", "w", stdout);
}
int test_case = 1;
// cin >> test_case;
// prepare();
for (int i = 1; i <= test_case; ++ i) {
solve(i);
// bf();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(".ou", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
knapsack.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(Task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | 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... |