結果

問題 No.5 数字のブロック
ユーザー n3k2t1n3k2t1
提出日時 2019-07-07 19:39:40
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 969 ms / 5,000 ms
コード長 636 bytes
コンパイル時間 33 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 45,136 KB
最終ジャッジ日時 2024-04-21 02:39:33
合計ジャッジ時間 10,037 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
40,064 KB
testcase_01 AC 74 ms
39,680 KB
testcase_02 AC 70 ms
40,064 KB
testcase_03 AC 625 ms
44,416 KB
testcase_04 AC 86 ms
44,004 KB
testcase_05 AC 680 ms
44,544 KB
testcase_06 AC 346 ms
44,288 KB
testcase_07 AC 480 ms
44,416 KB
testcase_08 AC 322 ms
44,288 KB
testcase_09 AC 168 ms
44,032 KB
testcase_10 AC 454 ms
44,416 KB
testcase_11 AC 175 ms
44,160 KB
testcase_12 AC 611 ms
44,288 KB
testcase_13 AC 461 ms
44,416 KB
testcase_14 AC 96 ms
43,904 KB
testcase_15 AC 87 ms
43,904 KB
testcase_16 AC 645 ms
44,416 KB
testcase_17 AC 808 ms
44,616 KB
testcase_18 AC 589 ms
44,180 KB
testcase_19 AC 969 ms
45,136 KB
testcase_20 AC 70 ms
40,192 KB
testcase_21 AC 70 ms
40,064 KB
testcase_22 AC 66 ms
39,680 KB
testcase_23 AC 71 ms
40,064 KB
testcase_24 AC 81 ms
44,032 KB
testcase_25 AC 139 ms
44,160 KB
testcase_26 AC 70 ms
39,936 KB
testcase_27 AC 70 ms
39,808 KB
testcase_28 AC 72 ms
40,192 KB
testcase_29 AC 88 ms
43,872 KB
testcase_30 AC 110 ms
43,680 KB
testcase_31 AC 71 ms
40,192 KB
testcase_32 AC 78 ms
39,936 KB
testcase_33 AC 69 ms
39,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
let L, N, W;

//
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', data => {
  const arr = data.split('\n');
  L = Number(arr[0]);
  N = Number(arr[1]);
  W = arr[2].split(' ').map(x => Number(x));
});

process.stdin.on('end', () => {

  let dp0 = new Array(L + 1).fill(0);
  let dp1 = new Array(L + 1).fill(0);

  for (let i = 0; i < N; i++) {

    [dp0, dp1] = [dp1, dp0];
    dp1.fill(0);

    for (let j = 0; j <= L; j++) {
      if (j < W[i]) {
        dp1[j] = dp0[j];
      } else {
        dp1[j] = Math.max(dp0[j], dp0[j - W[i]] + 1);
      }
    }
  }
  console.log(Math.max(dp1[L]));
});
0