結果

問題 No.472 平均順位
コンテスト
ユーザー yuppe19 😺
提出日時 2016-12-22 12:45:43
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 793 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,440 ms
コンパイル使用メモリ 173,452 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:08:06
合計ジャッジ時間 3,250 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   int n, p; scanf("%d%d", &n, &p);
      |             ~~~~~^~~~~~~~~~~~~~~~
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d%d%d", &mat[0][i], &mat[1][i], &mat[2][i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
using namespace std;

constexpr int inf = 987654321;

int main(void) {
  int n, p; scanf("%d%d", &n, &p);
  vector<vector<int>> mat(4, vector<int>(n)); // mat[4][n]
  for(int i=0; i<n; ++i) {
    scanf("%d%d%d", &mat[0][i], &mat[1][i], &mat[2][i]);
    mat[3][i] = 1;
  }
  vector<vector<int>> dp(2, vector<int>(p+1, inf)); // dp[2][p+1]
  dp[0][0] = 0;
  for(int i=0; i<n; ++i) {
    int cur = i & 1,
        nxt = (i+1) & 1;
    for(int j=0; j<=p; ++j) {
      if(dp[cur][j] == inf) { continue; }
      for(int k=0; k<=3 && j+k<=p; ++k) {
        dp[nxt][j+k] = min(dp[nxt][j+k], dp[cur][j] + mat[k][i]);
      }
    }
    dp[cur].assign(p+1, inf);
  }
  int res = dp[n&1][p];
  double ave = double(res) / n;
  printf("%.10lf\n", ave);
  return 0;
}
0