結果

問題 No.472 平均順位
ユーザー chocobochocobo
提出日時 2018-09-14 16:11:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 100,912 KB
実行使用メモリ 590,132 KB
最終ジャッジ日時 2023-09-19 05:46:52
合計ジャッジ時間 6,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
6,540 KB
testcase_09 AC 24 ms
18,936 KB
testcase_10 AC 16 ms
12,804 KB
testcase_11 AC 69 ms
53,060 KB
testcase_12 AC 50 ms
38,296 KB
testcase_13 AC 181 ms
133,976 KB
testcase_14 MLE -
testcase_15 AC 183 ms
133,920 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 49 ms
37,372 KB
testcase_19 AC 89 ms
65,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




int main() {
    ll n, p;
    cin >> n >> p;
    vector<ll> a(n), b(n), c(n);
    REP(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    vector<vector<ll>> dp(n + 5, vector<ll>(p + 5, INF));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    dp[0][3] = 1;
    for(ll i = 0; i < n - 1; i++){
        for(ll j = 0; j <= p; j++){
            if(j <= p - 3){
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]);
                dp[i + 1][j + 2] = min(dp[i + 1][j + 2], dp[i][j] + c[i + 1]);
                dp[i + 1][j + 3] = min(dp[i + 1][j + 3], dp[i][j] + 1);
            }
            else if(j == p - 2){
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]);
                dp[i + 1][j + 2] = min(dp[i + 1][j + 2], dp[i][j] + c[i + 1]);
            }
            else if(j == p - 1){
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]);
            }
            else{
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]);
            }
        }
    }
    
    printf("%.7lf\n", (double)dp[n - 1][p] / (double)n);
}
0