結果

問題 No.37 遊園地のアトラクション
ユーザー bal4ubal4u
提出日時 2019-07-01 06:39:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 20:10:33
合計ジャッジ時間 1,080 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.37 遊園地のアトラクション
// 2019.7.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int N, T;
int c[16];
int sc[16][10], sv[16][10], sz[16];
int dp[16][11005];

inline static int MAX(int a, int b) { if (a < b) a = b; return a; }

int main()
{
	int i, j, k, t;

	T = in(), N = in();
	for (i = 1; i <= N; i++) c[i] = in();
	for (i = 1; i <= N; i++) {
		k = in();
		sc[i][0] = sv[i][0] = 0;
		for (j = 1; k; j++) {
			sc[i][j] = sc[i][j-1] + c[i];
			sv[i][j] = sv[i][j-1] + k;
			k >>= 1;
		}
		sz[i] = j;
	}

	dp[0][0] = 1;
	for (i = 1; i <= N; i++) {
		for (j = sz[i]-1; j >= 0; j--) {
			for (t = T; t >= 0; t--) if (dp[i-1][t]) {
				dp[i][t+sc[i][j]] = MAX(dp[i][t+sc[i][j]], dp[i-1][t]+sv[i][j]);
			}
		}
	}
	
	k = 0;
	for (t = T; t >= 0; t--) if (dp[N][t] > k) k = dp[N][t];
	printf("%d\n", k-1);
	return 0;
}
0