結果

問題 No.472 平均順位
ユーザー tomorrowtomorrow
提出日時 2022-05-18 03:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 2,095 ms
コンパイル使用メモリ 200,916 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 07:10:55
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
4,352 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 11 ms
4,352 KB
testcase_13 AC 69 ms
4,348 KB
testcase_14 AC 69 ms
4,348 KB
testcase_15 AC 69 ms
4,352 KB
testcase_16 AC 68 ms
4,348 KB
testcase_17 AC 62 ms
4,352 KB
testcase_18 AC 6 ms
4,352 KB
testcase_19 AC 61 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[15005];
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];
    }
    for (ll j = 0; j < 15005; ++j) {
        dp[j] = (1 << 30);
    }
    dp[0] = 0;
    for (ll i = 0; i < n; ++i) {
        for (ll j = 3 * (i + 1); j >= 0; --j) {
            dp[j] = dp[j] + a[i];
            if (j >= 3) {
                chmin(dp[j], dp[j - 3] + 1);
            }
            if (j >= 2) {
                chmin(dp[j], dp[j - 2] + c[i]);
            }
            if (j >= 1) {
                chmin(dp[j], dp[j - 1] + b[i]);
            }
            //for (ll t = 0; t < 4; ++t) {
            //    cout << dp[t] << endl;
            //}
        }
    }
    cout << fixed << setprecision(10) << static_cast<double>(dp[p]) / n << endl;
}
0