結果

問題 No.472 平均順位
ユーザー sugarrrsugarrr
提出日時 2018-01-04 00:29:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 76,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 18:07:27
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 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 3 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 50 ms
4,376 KB
testcase_14 AC 174 ms
4,376 KB
testcase_15 AC 51 ms
4,380 KB
testcase_16 AC 201 ms
4,384 KB
testcase_17 AC 214 ms
4,380 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 26 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;
int min4(int a,int b,int c,int d){
    if(a<b)b=a;
    if(b<c)c=b;
    if(c<d)d=c;
    return d;
}
int min3(int a,int b,int c){
    if(a<b)b=a;
    if(b<c)c=b;
    return c;
}
int main(){
    int n,p;cin>>n>>p;
    int a[n+1],b[n+1],c[n+1];for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
    int dp[2][p+1];
    for(int j=0;j<=p;j++)dp[0][j]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=p;j++){
        if(j==0)dp[1][j]=dp[0][j]+a[i];
        else if(j==1)dp[1][j]=min(dp[0][j]+a[i],dp[0][j-1]+b[i]);
        else if(j==2)dp[1][j]=min3(dp[0][j]+a[i],dp[0][j-1]+b[i],dp[0][j-2]+c[i]);
        else dp[1][j]=min4(dp[0][j]+a[i],dp[0][j-1]+b[i],dp[0][j-2]+c[i],dp[0][j-3]+1);
        }
        for(int j=0;j<=p;j++)dp[0][j]=dp[1][j];
    }
    cout<<(double)dp[1][p]/n<<endl;
    
    
    return 0;
}
0