結果

問題 No.472 平均順位
ユーザー あっちむいてホイ!あっちむいてホイ!
提出日時 2021-08-23 14:57:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 141,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:06:37
合計ジャッジ時間 2,698 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 51 ms
5,376 KB
testcase_14 AC 133 ms
5,376 KB
testcase_15 AC 49 ms
5,376 KB
testcase_16 AC 143 ms
5,376 KB
testcase_17 AC 133 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 27 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <bitset>
#include <map>
#include <set>
#include <queue>
using namespace std;

int main(int argc, char const *argv[])
{
  int N,P ; cin >> N >> P;
  vector<int> A(N),B(N),C(N);
  for(int i=0;i<N;++i)
  {
    cin >> A[i] >> B[i] >> C[i];
  }
  const int INF = 1e9;
  auto chmin = [](int &x, int y) -> int
  {
    if(y < x)x = y;
    return x;
  };
  vector<int> dp(P+1,INF);
  vector<int> ndp(P+1,INF);
  dp[0] = 0;
  for(int i=0;i<N;++i)
  {
    for(int j=P;j>=0;--j)
    {
      if(dp[j] != INF)
      {
        chmin(ndp[j],dp[j]+A[i]);
        if(j+1 <= P)chmin(ndp[j+1], dp[j]+B[i]);
        if(j+2 <= P)chmin(ndp[j+2], dp[j]+C[i]);
        if(j+3 <= P)chmin(ndp[j+3],dp[j]+1);
      }
    }
    dp = ndp;
    for(auto &x: ndp) x = INF;
  }
  
  std::cout << std::fixed << std::setprecision(15) << (double)dp[P]/N << std::endl;
}
0