結果

問題 No.472 平均順位
ユーザー Teruya-HimakiTeruya-Himaki
提出日時 2017-09-20 17:52:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,293 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 171,252 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-25 21:14:20
合計ジャッジ時間 5,919 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,880 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 138 ms
6,940 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 49 ms
6,944 KB
testcase_07 AC 469 ms
6,944 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n,p;cin>>n>>p;
    vector<vector<int> > data(n,vector<int>(3));
    REP(i,n){
        REP(j,3){
            cin>>data[i][j];
        }
    }
    vector<vector<int> > memo(n,vector<int>(p+1));
    vector<vector<bool> > done(n,vector<bool>(p+1));
    function<int (int,int)> func=[=,&func,&done,&memo](int depth,int remain){
        cerr<<"Called:"<<depth<<","<<remain<<endl;
        if(depth==n){
            if(remain==0){
                cerr<<"Returned 0"<<endl;
                return 0;
            }else{
                cerr<<"Returned INF"<<endl;
                return 1<<30;
            }
        }
        if(remain<0){
            cerr<<"Not remained"<<endl;
            return 1<<30;
        }
        if(done[depth][remain]==true){
            return memo[depth][remain];
        }
        done[depth][remain]=true;
        int res=1<<30;
        REP(i,3){
            res=min(res,func(depth+1,remain-i)+data[depth][i]);
        }
        res=min(res,func(depth+1,remain-3)+1);
        return memo[depth][remain]=res;
    };
    cout<<fixed<<setprecision(5)<<(double)func(0,p)/n<<endl;
    return 0;
}
0