제출 #1322656

#제출 시각아이디문제언어결과실행 시간메모리
1322656trandinhnhatKnapsack (NOI18_knapsack)C++20
0 / 100
1096 ms2360 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define str string #define ch char #define task "" #define pb push_back #define ii pair<ll,ll> #define iii pair <ll, ii> #define fi first #define se second using namespace std; template<class X, class Y> bool maximize(X &x, const Y &y) { return (x < y) ? (x = y, true) : false; } template<class X, class Y> bool minimize(X &x, const Y &y) { return (x > y) ? (x = y, true) : false; } const ll mod = 1e9 + 7; const ll N = 5005; const ll inf = LLONG_MAX; const ll SHIFT = 1e6; ll a[N], w[N], v[N], dp[N][N]; ll n, s; void sub1(); void sub2(); void sub3(); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } cin >> s >> n; for (ll i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> a[i]; } for (ll i = 1; i <= n; i++) { for (ll j = s; j >= w[i]; j--) { for (ll k = 0; k <= a[i]; k++) { dp[i][j] = max(dp[i][j], dp[i - 1][j]); if (j - k * w[i] >= 0) { dp[i][j] = max(dp[i][j], dp[i - 1][j - k * w[i]] + k * v[i]); } } } } cout << dp[n][s]; return 0; } /*Set the pace, set the goal, maintain your streak by solving problem everyday*/ /* ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⣠⡀⠀⠀⠀⠀⠀⣀⣴⠞⠀⠀⠀⠀⠀⠀ ⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⡼⣿⠀⠀⠀⣀⠴⠋⢡⠎⠀⠀⣀⡠⠴⠒⢉⠟⠁⠀⠀⠀ ⣀⣠⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⢠⡄⠀⠀⠀⢠⠎⠀⡇⢀⡠⠚⠁⠀⢀⡯⠤⠚⠋⠁⠀⢀⡴⢃⣀⠤⠖⠛⠉⣠⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⡜⢧⠀⠀⣰⠋⠀⢠⡧⠋⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠰⠞⠋⠉⠀⠀⠀⢀⡜⠁⣀⣀⣀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⣰⠁⢸⡀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠋⠉⠉⠉⠉⠉⠉⢉⡭⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢀⡏⠀⠀⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠖⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⣋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⣀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠙⣟⠒⠤⡧⠀⠀⠀⠀⠀⠀⠀⠐⢦⠀⠀⠀⠀⣄⠀⠀⠀⠀⢶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠈⢦⠀⠀⠀⠀⠀⢀⣤⣴⣶⠿⢿⣷⣦⡀⠀⠘⣷⡄⠀⠀⠀⢳⣄⠀⠀⠀⠀⠰⡄⠀⠀⠀⠀⠀⠐⢶⠲⠤⣤⣌⡑⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠈⢳⡀⣠⣴⡾⠟⠉⠁⠀⠀⠈⢸⣿⣿⣦⡀⠈⢿⣶⣄⠀⠈⢻⣿⣶⣄⠀⠀⢹⣄⠀⠀⠀⠀⠀⠈⠳⡀⠀⠀⠈⠉⠃⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⡿⢟⢁⡀⠀⢀⣀⡤⠶⠒⠛⣿⣿⣿⣿⣦⣌⢿⣿⣿⣦⡀⢿⣿⣿⣿⣦⣄⣿⣷⣄⠀⠀⢷⠤⣀⠹⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⣼⡁⢰⣸⣷⠞⠋⠀⠀⠀⠀⠤⢿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣷⣿⣿⣿⠿⣿⣿⣿⣿⣷⣄⠸⡆⠈⠙⠾⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⢿⣽⡿⡏⠛⠀⠀⠀⣀⣤⣶⣶⣾⣿⡿⠿⠛⠛⠉⣏⠉⠁⠀⢰⠟⣯⣾⡟⠻⣿⡍⠉⠛⣟⠳⣽⡀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⢸⠟⠃⠀⢀⣤⣶⣿⣿⣿⡿⣋⡭⣄⠀⠀⠀⠀⠀⠘⣆⠀⠀⡏⠀⣿⣿⣧⡀⢿⡷⠀⠀⠘⣄⠈⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠈⡇⣀⣶⣾⣿⠿⣫⢿⢟⣵⣾⣟⣻⠀⠀⠀⠀⠀⠀⠹⣶⡀⡇⠀⠈⣿⣇⠇⣾⡷⠀⠀⠀⠘⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠻⣿⣿⡋⠀⠸⠁⠎⣿⣿⣟⡿⠇⠀⠀⠀⠀⠀⠀⠀⠯⢳⡇⠀⠀⠛⠋⣸⣿⠆⠀⠀⠀⢤⣜⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⢻⣳⡆⢠⣶⡆⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠀⠀⣀⣀⣽⡋⠀⠀⠀⠀⠘⣏⠛⢧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠘⢿⡇⢰⣿⡗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡟⡏⢷⠀⠀⠀⠀⣤⡘⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⠁⠰⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣇⠃⠈⡆⠀⠀⠀⢹⡙⢿⡀⠀⠀⣀⣀⣠⣤⣤⡄⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⢹⣄⣀⣀⣼⣷⣶⣾⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠈⠳⢴⣯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡀⢀⣀⡤⠤⠄⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣏⡠⢤⣴⠄⠀⠀⠀⢀⣠⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣄⠀⠛⢀⣠⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣸⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⣽⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀ ⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀ ⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷ */

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...