結果

問題 No.472 平均順位
ユーザー chocobochocobo
提出日時 2018-09-14 16:20:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 1,716 bytes
コンパイル時間 1,100 ms
コンパイル使用メモリ 98,640 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 05:58:47
合計ジャッジ時間 3,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 34 ms
4,380 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 87 ms
4,380 KB
testcase_14 AC 308 ms
4,376 KB
testcase_15 AC 86 ms
4,380 KB
testcase_16 AC 348 ms
4,380 KB
testcase_17 AC 374 ms
4,380 KB
testcase_18 AC 23 ms
4,384 KB
testcase_19 AC 42 ms
4,376 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<ll> dp(p + 5, INF);
    dp[0] = a[0];
    dp[1] = b[0];
    dp[2] = c[0];
    dp[3] = 1;
    for(ll i = 0; i < n - 1; i++){
        vector<ll> tmp(p + 5, INF);
        for(ll j = 0; j <= p; j++){
            if(j <= p - 3){
                tmp[j] = min(tmp[j], dp[j] + a[i + 1]);
                tmp[j + 1] = min(tmp[j + 1], dp[j] + b[i + 1]);
                tmp[j + 2] = min(tmp[j + 2], dp[j] + c[i + 1]);
                tmp[j + 3] = min(tmp[j + 3], dp[j] + 1);
            }
            else if(j == p - 2){
                tmp[j] = min(tmp[j], dp[j] + a[i + 1]);
                tmp[j + 1] = min(tmp[j + 1], dp[j] + b[i + 1]);
                tmp[j + 2] = min(tmp[j + 2], dp[j] + c[i + 1]);
            }
            else if(j == p - 1){
                tmp[j] = min(tmp[j], dp[j] + a[i + 1]);
                tmp[j + 1] = min(tmp[j + 1], dp[j] + b[i + 1]);
            }
            else{
                tmp[j] = min(tmp[j], dp[j] + a[i + 1]);
            }
        }
        dp = tmp;
    }
    
    printf("%.7lf\n", (double)dp[p] / (double)n);
}
0