| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 716626 | farica | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef vector<int> vi;
const int INF = 1e9;
const int MX = 5e5 + 23;
const int MOD = 1e9+7;
const int MAX_N = 1e6;
const int MAX_N2 = 1e5;
const int TWO_MOD_INV = 500000004;
const int M = 998244353;
void solve() {
int n,s;
cin >> s >> n;
map<int, vector<pair<int,int>>>ma;
for(int i=0; i<n; ++i) {
int val, weight, am;
cin >> val >> weight >> am;
ma[weight].push_back({val, am});
}
vector<vector<long long>>dp(ma.size()+1, vector<long long>(s+1, INT32_MIN));
dp[0][0]=0;
int pos=1;
ll ans=0;
for(auto &[w, items]: ma) {
sort(items.begin(), items.end(), greater<pair<int,int>>());
for(int i=0; i<=s; ++i) {
dp[pos][s]=dp[pos-1][s];
int cnt=0, num=0, us=0;
ll profit=0;
while(cnt<items.size() && w*(num+1)<=i) {
++num;
profit+=items[cnt].first;
if(dp[pos-1][i-w*num]!=INT32_MIN) dp[pos][i]=max(dp[pos][i], dp[pos-1][i-w*num]+profit);
++us;
if(items[cnt].second==us) {
++cnt;
us=0;
}
}
ans=max(ans, dp[pos][i]);
}
++pos;
}
cout << ans << endl;
}
int main()
{
//freopen("feast.in","r",stdin);
//freopen("feast.out","w",stdout);
int t=1;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
