結果

問題 No.385 カップ麺生活
ユーザー リチウムリチウム
提出日時 2016-07-02 00:57:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 3,485 ms
コンパイル使用メモリ 77,524 KB
実行使用メモリ 54,564 KB
最終ジャッジ日時 2024-04-15 07:29:47
合計ジャッジ時間 9,577 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
54,188 KB
testcase_01 AC 138 ms
54,244 KB
testcase_02 AC 136 ms
53,864 KB
testcase_03 AC 143 ms
54,300 KB
testcase_04 AC 141 ms
54,352 KB
testcase_05 AC 138 ms
54,204 KB
testcase_06 AC 140 ms
54,412 KB
testcase_07 AC 139 ms
54,128 KB
testcase_08 AC 137 ms
54,128 KB
testcase_09 AC 138 ms
54,328 KB
testcase_10 AC 152 ms
54,256 KB
testcase_11 AC 132 ms
53,896 KB
testcase_12 AC 137 ms
54,104 KB
testcase_13 AC 143 ms
54,068 KB
testcase_14 AC 143 ms
54,476 KB
testcase_15 AC 146 ms
54,404 KB
testcase_16 AC 137 ms
54,124 KB
testcase_17 AC 155 ms
54,436 KB
testcase_18 AC 138 ms
54,116 KB
testcase_19 AC 136 ms
54,244 KB
testcase_20 AC 145 ms
54,340 KB
testcase_21 AC 142 ms
54,324 KB
testcase_22 AC 147 ms
54,212 KB
testcase_23 AC 143 ms
54,096 KB
testcase_24 AC 143 ms
54,416 KB
testcase_25 AC 134 ms
54,012 KB
testcase_26 AC 133 ms
54,116 KB
testcase_27 AC 141 ms
53,996 KB
testcase_28 AC 145 ms
54,292 KB
testcase_29 AC 137 ms
54,136 KB
testcase_30 AC 138 ms
53,888 KB
testcase_31 AC 133 ms
54,156 KB
testcase_32 AC 133 ms
54,564 KB
testcase_33 AC 144 ms
54,220 KB
testcase_34 AC 137 ms
54,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test;

import java.util.Arrays;
import java.util.Scanner;


public class atc {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		int n=sc.nextInt();
		int[]c=new int[n];
		for(int i=0;i<n;i++){
			c[i]=sc.nextInt();
		}
		Arrays.sort(c);
		int d[]=new int[m+1];
		Arrays.fill(d,-1);
		d[0]=0;
		for(int i=0;i<=m;i++){
			for(int j=0;j<n;j++){
				if(i-c[j]>=0 && d[i-c[j]]>-1)d[i]=Math.max(d[i],d[i-c[j]]+1);
			}
		}
		long ans=0;
		for(int i=1;i<m;i++){
			if(d[i]>-1 && prime(m-i))ans+=d[i];
		}
		ans+=m/c[0];
		System.out.println(ans);
	}
	
	static boolean prime(int n){
		if(n==1)return false;
		if(n==2 || n==3)return true;
		for(int i=2;i<=Math.sqrt(n);i++){
			if(n%i==0)return false;
		}
		return true;
	}

}
0