結果

問題 No.472 平均順位
ユーザー tomorrow
提出日時 2022-05-18 01:33:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,143 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 197,812 KB
最終ジャッジ日時 2025-01-29 09:04:21
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T& a, const T& b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr ll inf = (1LL << 62);
int main()
{
    ll n, p;
    cin >> n >> p;
    vector<int> a(n), b(n), c(n);
    vector<vector<int>> dp(n + 1, vector<int>(p + 1, (1 << 30)));
    for (ll i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    //int dp[5005][15005];
    dp[0][0] = 0;
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j <= p; ++j) {
            if (j >= 3) {
                chmin(dp[i + 1][j], dp[i][j - 3] + 1);
            }
            if (j >= 2) {
                chmin(dp[i + 1][j], dp[i][j - 2] + c[i]);
            }
            if (j >= 1) {
                chmin(dp[i + 1][j], dp[i][j - 1] + b[i]);
            }
            chmin(dp[i + 1][j], dp[i][j] + a[i]);
        }
    }
    cout << fixed << setprecision(10) << static_cast<double>(dp[n][p]) / n << endl;
}
0