結果

問題 No.472 平均順位
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-12-22 00:48:08
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 884 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 51,576 KB
最終ジャッジ日時 2023-08-22 15:01:37
合計ジャッジ時間 855 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:8:1: error: ‘vector’ does not name a type; did you mean ‘perror’?
 vector<vector<int>> mat, dp;
 ^~~~~~
 perror
main.cpp: In function ‘int main()’:
main.cpp:12:3: error: ‘mat’ was not declared in this scope
   mat.assign(3, vector<int>(n));
   ^~~
main.cpp:12:3: note: suggested alternative: ‘main’
   mat.assign(3, vector<int>(n));
   ^~~
   main
main.cpp:12:17: error: ‘vector’ was not declared in this scope
   mat.assign(3, vector<int>(n));
                 ^~~~~~
main.cpp:12:17: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:12:17:
   mat.assign(3, vector<int>(n));
                 ^~~~~~
main.cpp:12:24: error: expected primary-expression before ‘int’
   mat.assign(3, vector<int>(n));
                        ^~~
main.cpp:16:3: error: ‘dp’ was not declared in this scope
   dp.assign(2, vector<int>(p+1, inf));
   ^~
main.cpp:16:3: note: suggested alternative: ‘p’
   dp.assign(2, vector<int>(p+1, inf));
   ^~
   p
main.cpp:16:23: error: expected primary-expression before ‘int’
   dp.assign(2, vector<int>(p+1, inf));
                       ^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;

constexpr int inf = 987654321;
int n, p;
vector<vector<int>> mat, dp;

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