結果

問題 No.472 平均順位
ユーザー megasharesmegashares
提出日時 2018-09-12 22:41:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 28,208 KB
実行使用メモリ 5,052 KB
最終ジャッジ日時 2023-09-10 08:45:43
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 14 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 34 ms
4,380 KB
testcase_13 AC 140 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 140 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 360 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 71 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:26: warning: ‘now’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  printf("%.1lf", f[now][p] / (double)n);
                  ~~~~~~~~^

ソースコード

diff #

#include <stdio.h>

double f[3][15010] = {};

double min(double a, double i, double b, double j) {
	return a / i < b / j ? 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, old;
	for (i = 2; i <= n; i++) {
		for (j = 0; j <= p; j++) {
			if (j > 3 * i) continue;

			now = i % 2 == 0 ? 2 : 1;
			old = now == 1 ? 2 : 1;

			if (j <= (i - 1) * 3) {
				f[now][j] = (f[old][j] + arr[i].a);

				if (j - 1 >= 0) f[now][j] = min(f[now][j], i, (f[old][j - 1] + arr[i].b), i);
				if (j - 2 >= 0) f[now][j] = min(f[now][j], i, (f[old][j - 2] + arr[i].c), i);
				if (j - 3 >= 0) f[now][j] = min(f[now][j], i, (f[old][j - 3] + 1.0), i);
			}
			else
			{
				int d = j - (i - 1) * 3;

				switch (d)
				{
				case 1:
					f[now][j] = f[old][j - 1] + arr[i].b;
					break;

				case 2:
					f[now][j] = f[old][j - 2] + arr[i].c;
					break;
 
				case 3:
					f[now][j] = f[old][j - 3] + 1.0;
					break;
				}
			}
		}
	}

	printf("%.1lf", f[now][p] / (double)n);

	getchar(); getchar();
	return 0;
}
0