結果

問題 No.472 平均順位
ユーザー roarisroaris
提出日時 2019-12-16 16:02:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 167,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 17:45:26
合計ジャッジ時間 3,672 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 34 ms
4,376 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 87 ms
4,380 KB
testcase_14 AC 307 ms
4,380 KB
testcase_15 AC 87 ms
4,376 KB
testcase_16 AC 353 ms
4,380 KB
testcase_17 AC 374 ms
4,376 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 44 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000

int main() {
    int N, P; cin >> N >> P;
    int a[N], b[N], c[N];
    
    for (int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];
    
    int dp[2][P+1];
    
    for (int i=0; i<=P; i++) {
        dp[0][i] = 0;
    }
    
    for (int i=0; i<N; i++) {
        for (int j=0; j<=P; j++) {
            dp[(i+1)&1][j] = INF;
        }
        
        for (int j=0; j<=P; j++) {
            dp[(i+1)&1][j] = min(dp[(i+1)&1][j], dp[i&1][j]+a[i]);
            
            if (j+1<=P) {
                dp[(i+1)&1][j+1] = min(dp[(i+1)&1][j+1], dp[i&1][j]+b[i]);
            }
            
            if (j+2<=P) {
                dp[(i+1)&1][j+2] = min(dp[(i+1)&1][j+2], dp[i&1][j]+c[i]);
            }
            
            if (j+3<=P) {
                dp[(i+1)&1][j+3] = min(dp[(i+1)&1][j+3], dp[i&1][j]+1);
            }
        }
    }
    
    cout << setprecision(10) << (float)dp[N&1][P]/N << endl;
}
0