結果

問題 No.472 平均順位
ユーザー 0w10w1
提出日時 2018-05-08 21:25:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 204,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 11:08:01
合計ジャッジ時間 4,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 29 ms
4,380 KB
testcase_12 AC 20 ms
4,376 KB
testcase_13 AC 71 ms
4,376 KB
testcase_14 AC 253 ms
4,376 KB
testcase_15 AC 72 ms
4,376 KB
testcase_16 AC 289 ms
4,376 KB
testcase_17 AC 308 ms
4,376 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  int n, p;
  cin >> n >> p;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(2, vector<int>(p + 1, 0x3f3f3f3f));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    dp[~i & 1] = vector<int>(p + 1, 0x3f3f3f3f);
    for (int j = 0; j <= p; ++j) {
      dp[~i & 1][j] = min(dp[~i & 1][j], dp[i & 1][j] + a[i]);
      if (j + 1 <= p) {
        dp[~i & 1][j + 1] = min(dp[~i & 1][j + 1], dp[i & 1][j] + b[i]);
      }
      if (j + 2 <= p) {
        dp[~i & 1][j + 2] = min(dp[~i & 1][j + 2], dp[i & 1][j] + c[i]);
      }
      if (j + 3 <= p) {
        dp[~i & 1][j + 3] = min(dp[~i & 1][j + 3], dp[i & 1][j] + 1);
      }
    }
  }
  cout << fixed << setprecision(7) << (1.0 * dp[n & 1][p] / n) << endl;
  return 0;
}
0