| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1043191 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 249 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bip(i) __builtin_popcount(i)
#define gb(i,j) ((i>>j)&1)
#define se second
#define fi first
using namespace std;
const int N=2005;
int n , S;
ll f[N] , res;
vector<pair<int,int>>vec[N] , prc;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> S >> n;
for( int i=1 ; i<=n ; i++ ){
int v , w , fre;
cin >> v >> w >> fre;
vec[w].push_back({v , fre});
}
prc.push_back({0,0});
for( int i=1 ; i<=S ; i++ ) // weight
if(vec[i].size()){
sort(vec[i].begin() , vec[i].end() , greater<pair<int,int>>() );
for( auto [val , fr]: vec[i] ){
int tmp=0 , ch=0;
for( int k=1 ; k<=fr ; k++ ){
tmp+=i;
if(tmp<=S)
prc.push_back({val , i});
else{
ch=1;
break;
}
}
if(ch)break;
}
}
for( int i=1 ; i<prc.size() ; i++ ){
int val = prc[i].fi , wei = prc[i].se;
for( int j=S ; j>=0 ; j-- )if(j>=wei){
f[j] = max( f[j] , f[j-wei]+val ); // truong hop chon i
res = max( res , f[j] );
}else break;
}
cout << res;
}
컴파일 시 표준 에러 (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... | ||||
