結果
| 問題 |
No.472 平均順位
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-22 12:45:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 793 bytes |
| コンパイル時間 | 313 ms |
| コンパイル使用メモリ | 51,804 KB |
| 最終ジャッジ日時 | 2024-11-14 19:55:16 |
| 合計ジャッジ時間 | 964 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:3: error: ‘vector’ was not declared in this scope
9 | vector<vector<int>> mat(4, vector<int>(n)); // mat[4][n]
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:9:17: error: expected primary-expression before ‘int’
9 | vector<vector<int>> mat(4, vector<int>(n)); // mat[4][n]
| ^~~
main.cpp:11:22: error: ‘mat’ was not declared in this scope
11 | scanf("%d%d%d", &mat[0][i], &mat[1][i], &mat[2][i]);
| ^~~
main.cpp:14:17: error: expected primary-expression before ‘int’
14 | vector<vector<int>> dp(2, vector<int>(p+1, inf)); // dp[2][p+1]
| ^~~
main.cpp:15:3: error: ‘dp’ was not declared in this scope; did you mean ‘p’?
15 | dp[0][0] = 0;
| ^~
| p
main.cpp:22:55: error: ‘mat’ was not declared in this scope
22 | dp[nxt][j+k] = min(dp[nxt][j+k], dp[cur][j] + mat[k][i]);
| ^~~
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);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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;
}