結果

問題 No.472 平均順位
コンテスト
ユーザー siman
提出日時 2022-09-15 00:18:03
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 1,088 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 950 ms
コンパイル使用メモリ 152,064 KB
実行使用メモリ 590,080 KB
最終ジャッジ日時 2026-05-26 00:14:09
合計ジャッジ時間 3,966 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 MLE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   ll A[N];
      |        ^
main.cpp:20:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, P;
      |       ^
main.cpp:21:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   ll B[N];
      |        ^
main.cpp:21:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, P;
      |       ^
main.cpp:22:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   22 |   ll C[N];
      |        ^
main.cpp:22:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, P;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, P;
  cin >> N >> P;

  ll A[N];
  ll B[N];
  ll C[N];

  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i] >> C[i];
  }

  vector<vector<ll>> dp(N + 1, vector<ll>(P + 1, LLONG_MAX));
  dp[0][0] = 0;

  for (int i = 1; i <= N; ++i) {
    ll a = A[i - 1];
    ll b = B[i - 1];
    ll c = C[i - 1];

    for (int p = 0; p <= P; ++p) {
      if (dp[i - 1][p] != LLONG_MAX) {
        dp[i][p] = min(dp[i][p], dp[i - 1][p] + a);
        if (p + 1 <= P) {
          dp[i][p + 1] = min(dp[i][p + 1], dp[i - 1][p] + b);
        }
        if (p + 2 <= P) {
          dp[i][p + 2] = min(dp[i][p + 2], dp[i - 1][p] + c);
        }
        if (p + 3 <= P) {
          dp[i][p + 3] = min(dp[i][p + 3], dp[i - 1][p] + 1);
        }
      }
    }
  }

  cout << fixed << setprecision(10) << dp[N][P] * 1.0 / N << endl;

  return 0;
}
0