結果

問題 No.385 カップ麺生活
ユーザー htensaihtensai
提出日時 2020-05-14 11:37:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 77,444 KB
実行使用メモリ 54,564 KB
最終ジャッジ日時 2024-04-15 07:41:15
合計ジャッジ時間 8,428 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,400 KB
testcase_01 AC 133 ms
54,168 KB
testcase_02 AC 130 ms
54,004 KB
testcase_03 AC 131 ms
54,208 KB
testcase_04 AC 149 ms
54,096 KB
testcase_05 AC 130 ms
54,028 KB
testcase_06 AC 138 ms
53,632 KB
testcase_07 AC 137 ms
54,060 KB
testcase_08 AC 133 ms
54,504 KB
testcase_09 AC 130 ms
54,056 KB
testcase_10 AC 391 ms
54,256 KB
testcase_11 AC 133 ms
54,036 KB
testcase_12 AC 144 ms
54,008 KB
testcase_13 AC 147 ms
54,236 KB
testcase_14 AC 161 ms
54,120 KB
testcase_15 AC 144 ms
54,068 KB
testcase_16 AC 132 ms
54,264 KB
testcase_17 AC 155 ms
54,424 KB
testcase_18 AC 132 ms
53,896 KB
testcase_19 AC 137 ms
54,564 KB
testcase_20 AC 147 ms
54,252 KB
testcase_21 AC 144 ms
54,236 KB
testcase_22 AC 151 ms
54,104 KB
testcase_23 AC 144 ms
54,008 KB
testcase_24 AC 156 ms
53,580 KB
testcase_25 AC 132 ms
54,116 KB
testcase_26 AC 134 ms
54,208 KB
testcase_27 AC 139 ms
54,424 KB
testcase_28 AC 139 ms
54,108 KB
testcase_29 AC 137 ms
54,028 KB
testcase_30 AC 146 ms
54,392 KB
testcase_31 AC 133 ms
54,160 KB
testcase_32 AC 133 ms
54,084 KB
testcase_33 AC 134 ms
53,600 KB
testcase_34 AC 131 ms
54,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int[] dp = new int[m + 1];
		for (int i = 0; i < n; i++) {
		   int p = sc.nextInt();
		   min = Math.min(min, p);
		   for (int j = 0; j <= m - p; j++) {
		       if (j > 0 && dp[j] == 0) {
		           continue;
		       }
		       for (int k = 1; j + k * p <= m; k++) {
		           dp[j + k * p] = Math.max(dp[j + k * p], dp[j] + k);
		       }
		   }
		}
		long ans = m / min;
		for (int i = 2; i < m; i++) {
		    if (isPrime(i)) {
		        ans += dp[m - i];
		    }
		}
		System.out.println(ans);
	}
	
	static boolean isPrime(int x) {
	    for (int i = 2; i <= Math.sqrt(x); i++) {
	        if (x % i == 0) {
	            return false;
	        }
	    }
	    return true;
	}
}
0