結果

問題 No.472 平均順位
ユーザー simansiman
提出日時 2022-09-15 00:26:39
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 105,300 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-21 21:50:24
合計ジャッジ時間 2,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 7 ms
4,384 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 17 ms
4,384 KB
testcase_13 AC 63 ms
4,384 KB
testcase_14 AC 166 ms
4,380 KB
testcase_15 AC 63 ms
4,380 KB
testcase_16 AC 179 ms
4,384 KB
testcase_17 AC 184 ms
4,388 KB
testcase_18 AC 13 ms
4,384 KB
testcase_19 AC 34 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, P;
  cin >> N >> P;

  int A[N];
  int B[N];
  int C[N];

  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i] >> C[i];
  }

  vector<int> dp(P + 1, INT_MAX);
  dp[0] = 0;

  for (int i = 1; i <= N; ++i) {
    int a = A[i - 1];
    int b = B[i - 1];
    int c = C[i - 1];
    vector<int> temp(P + 1, INT_MAX);

    for (int p = 0; p <= P; ++p) {
      if (dp[p] != INT_MAX) {
        temp[p] = min(temp[p], dp[p] + a);
        if (p + 1 <= P) {
          temp[p + 1] = min(temp[p + 1], dp[p] + b);
        }
        if (p + 2 <= P) {
          temp[p + 2] = min(temp[p + 2], dp[p] + c);
        }
        if (p + 3 <= P) {
          temp[p + 3] = min(temp[p + 3], dp[p] + 1);
        }
      }
    }

    dp = temp;
  }

  cout << fixed << setprecision(10) << dp[P] * 1.0 / N << endl;

  return 0;
}

0