結果

問題 No.472 平均順位
ユーザー 0w10w1
提出日時 2018-05-08 21:19:43
言語 JavaScript
(node v21.7.1)
結果
TLE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 52,268 KB
最終ジャッジ日時 2024-04-21 02:08:19
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
44,160 KB
testcase_01 AC 66 ms
38,656 KB
testcase_02 AC 60 ms
38,656 KB
testcase_03 AC 60 ms
38,784 KB
testcase_04 AC 61 ms
38,784 KB
testcase_05 AC 56 ms
38,656 KB
testcase_06 AC 60 ms
38,784 KB
testcase_07 AC 81 ms
42,496 KB
testcase_08 AC 119 ms
44,320 KB
testcase_09 AC 262 ms
44,252 KB
testcase_10 AC 197 ms
44,648 KB
testcase_11 AC 599 ms
46,216 KB
testcase_12 AC 478 ms
46,256 KB
testcase_13 AC 1,051 ms
52,268 KB
testcase_14 TLE -
testcase_15 AC 1,049 ms
52,256 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {

  let inputs = input.split('\n');

  let n, p;
  [n, p] = inputs[0].split(' ').map((e) => e - 0);

  let a = new Array(n);
  let b = new Array(n);
  let c = new Array(n);

  for (let i = 0; i < n; ++i) {
    [a[i], b[i], c[i]] = inputs[1 + i].split(' ').map((e) => e - 0);
  }

  let dp = new Array(2);
  dp[0] = new Array(p + 1).fill(10**9);
  dp[0][0] = 0;
  for (let i = 0; i < n; ++i) {
    dp[~i & 1] = new Array(p + 1).fill(10**9);
    for (let j = 0; j <= p; ++j) {
      dp[~i & 1][j] = Math.min(dp[~i & 1][j], dp[i & 1][j] + a[i]);
      if (j + 1 <= p) {
        dp[~i & 1][j + 1] = Math.min(dp[~i & 1][j + 1], dp[i & 1][j] + b[i]);
      }
      if (j + 2 <= p) {
        dp[~i & 1][j + 2] = Math.min(dp[~i & 1][j + 2], dp[i & 1][j] + c[i]);
      }
      if (j + 3 <= p) {
        dp[~i & 1][j + 3] = Math.min(dp[~i & 1][j + 3], dp[i & 1][j] + 1);
      }
    }
  }

  console.log('%s', (dp[n & 1][p] / n).toFixed(7));

}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
0