結果

問題 No.472 平均順位
コンテスト
ユーザー chocobo
提出日時 2018-09-14 16:20:09
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,716 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 735 ms
コンパイル使用メモリ 114,576 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-27 03:38:13
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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