結果
問題 | No.472 平均順位 |
ユーザー |
![]() |
提出日時 | 2018-09-13 10:39:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,011 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 24,448 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 04:21:34 |
合計ジャッジ時間 | 2,071 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d%d", &n, &p); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d%d%d", &arr[i].a, &arr[i].b, &arr[i].c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>#include <limits.h>long long f[3][20100] = {};long long min(long long a, long long b) {return a < b ? a : b;}int main() {int n, p;int i, j;struct {int a, b, c;} arr[5010];scanf("%d%d", &n, &p);for (i = 1; i <= n; i++) {scanf("%d%d%d", &arr[i].a, &arr[i].b, &arr[i].c);}f[1][0] = arr[1].a;f[1][1] = arr[1].b;f[1][2] = arr[1].c;f[1][3] = 1.0;int now = 1, old;for (i = 2; i <= n; i++) {for (j = 0; j <= p; j++) {if (j > 3 * i) break;now = i % 2 == 0 ? 2 : 1;old = now == 1 ? 2 : 1;f[now][j] = INT_MAX;if (j <= (i - 1) * 3) f[now][j] = (f[old][j] + arr[i].a);if (j - 1 >= 0 && j - 1 <= (i - 1) * 3) f[now][j] = min(f[now][j], (f[old][j - 1] + arr[i].b));if (j - 2 >= 0 && j - 2 <= (i - 1) * 3) f[now][j] = min(f[now][j], (f[old][j - 2] + arr[i].c));if (j - 3 >= 0 && j - 3 <= (i - 1) * 3) f[now][j] = min(f[now][j], (f[old][j - 3] + 1.0));}}printf("%.1lf\n", (double)f[now][p] / (double)n);return 0;}