結果

問題 No.37 遊園地のアトラクション
ユーザー ぴろずぴろず
提出日時 2014-12-16 21:31:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 1,064 bytes
コンパイル時間 3,898 ms
コンパイル使用メモリ 84,540 KB
実行使用メモリ 42,612 KB
最終ジャッジ日時 2024-04-18 19:30:36
合計ジャッジ時間 7,680 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
42,052 KB
testcase_01 AC 111 ms
41,208 KB
testcase_02 AC 144 ms
41,824 KB
testcase_03 AC 155 ms
41,752 KB
testcase_04 AC 151 ms
42,064 KB
testcase_05 AC 162 ms
41,676 KB
testcase_06 AC 153 ms
41,868 KB
testcase_07 AC 161 ms
42,612 KB
testcase_08 AC 130 ms
40,632 KB
testcase_09 AC 114 ms
40,296 KB
testcase_10 AC 160 ms
42,028 KB
testcase_11 AC 161 ms
41,984 KB
testcase_12 AC 136 ms
41,764 KB
testcase_13 AC 144 ms
41,628 KB
testcase_14 AC 154 ms
41,892 KB
testcase_15 AC 160 ms
41,760 KB
testcase_16 AC 135 ms
42,032 KB
testcase_17 AC 150 ms
42,204 KB
testcase_18 AC 151 ms
42,236 KB
testcase_19 AC 117 ms
40,024 KB
testcase_20 AC 147 ms
41,952 KB
testcase_21 AC 127 ms
41,348 KB
testcase_22 AC 155 ms
42,520 KB
testcase_23 AC 115 ms
41,308 KB
testcase_24 AC 116 ms
40,276 KB
testcase_25 AC 127 ms
41,496 KB
testcase_26 AC 119 ms
41,400 KB
testcase_27 AC 148 ms
41,680 KB
testcase_28 AC 122 ms
41,272 KB
testcase_29 AC 134 ms
41,776 KB
testcase_30 AC 122 ms
41,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no037;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int n = sc.nextInt();
		int[] c = new int[n];
		int[] v = new int[n];
		int[][] v2 = new int[n][10];
		for(int i=0;i<n;i++) {
			c[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			v[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			for(int j=1;j<10;j++) {
				v2[i][j] = v2[i][j-1] + (v[i] >> (j-1));
			}
		}
//		System.out.println(Arrays.deepToString(v2));
		int[][] dp = new int[n+1][t+1];
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=t;j++) {
				dp[i][j] = dp[i-1][j];
				for(int k=1;k<10;k++) {
					int j2 = j - c[i-1] * k;
					if (j2 < 0) {
						break;
					}
					dp[i][j] = Math.max(dp[i][j], dp[i-1][j2] + v2[i-1][k]);
				}
			}
		}
//		System.out.println(Arrays.deepToString(dp));
		int ans = 0;
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=t;j++) {
				ans = Math.max(ans, dp[i][j]);
			}
		}
		System.out.println(ans);
	}

}
0