結果

問題 No.472 平均順位
ユーザー chocobochocobo
提出日時 2018-09-14 16:12:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,858 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 99,600 KB
実行使用メモリ 296,340 KB
最終ジャッジ日時 2023-09-19 05:47:57
合計ジャッジ時間 4,004 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
5,404 KB
testcase_09 AC 17 ms
10,912 KB
testcase_10 AC 12 ms
8,432 KB
testcase_11 AC 48 ms
27,844 KB
testcase_12 AC 35 ms
20,512 KB
testcase_13 AC 123 ms
68,432 KB
testcase_14 AC 436 ms
243,732 KB
testcase_15 AC 120 ms
68,564 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 33 ms
20,184 KB
testcase_19 AC 59 ms
34,316 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 int INF = 1e9;
const ll MOD = 1e9 + 7;

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




int main() {
    int n, p;
    cin >> n >> p;
    vector<int> a(n), b(n), c(n);
    REP(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    vector<vector<int>> dp(n, vector<int>(p + 4, 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