結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー lgswdnlgswdn
提出日時 2023-05-11 22:26:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 10,000 ms
コード長 1,106 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 201,488 KB
実行使用メモリ 53,456 KB
最終ジャッジ日時 2023-08-18 13:05:16
合計ジャッジ時間 8,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
6,064 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
5,848 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
5,840 KB
testcase_10 AC 2 ms
6,044 KB
testcase_11 AC 2 ms
5,928 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
5,832 KB
testcase_14 AC 2 ms
5,852 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
5,876 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
5,844 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
5,988 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 9 ms
12,224 KB
testcase_29 AC 9 ms
12,196 KB
testcase_30 AC 9 ms
12,484 KB
testcase_31 AC 9 ms
12,412 KB
testcase_32 AC 9 ms
12,244 KB
testcase_33 AC 11 ms
14,268 KB
testcase_34 AC 10 ms
12,224 KB
testcase_35 AC 8 ms
12,260 KB
testcase_36 AC 9 ms
12,232 KB
testcase_37 AC 9 ms
12,344 KB
testcase_38 AC 310 ms
53,456 KB
testcase_39 AC 294 ms
52,632 KB
testcase_40 AC 300 ms
52,624 KB
testcase_41 AC 323 ms
52,792 KB
testcase_42 AC 321 ms
52,652 KB
testcase_43 AC 319 ms
52,648 KB
testcase_44 AC 314 ms
52,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2509,inf=0x3f3f3f3f3f3f3f3f;
int n,c[N],v[N*12],f[N][N],tot;
typedef tuple<int,int,int> tiii;
tiii p[N*12];

signed main() {
  n=read();
  rep(i,1,n) c[i]=read(), v[i]=read();
  rep(i,1,n) rep(h,0,11) if(c[i]) {
    int x=min(c[i],1ll<<h); c[i]-=x;
    p[++tot]=tiii(i,x,v[i]);
  }
  rep(j,0,n) rep(k,0,n) f[j][k]=(j>0)*-inf;
  per(i,tot,1) {
    auto [w,c,v]=p[i];
    per(j,n/w,c) {
      per(k,n,w*c) {
        f[j][k]=max(f[j][k],f[j-c][k-w*c]+v*c);
      }
    }
  }
  rep(i,1,n) printf("%lld\n",f[i][n]);
  return 0;
}
0