結果
| 問題 |
No.385 カップ麺生活
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-02 00:57:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 155 ms / 2,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 4,046 ms |
| コンパイル使用メモリ | 78,104 KB |
| 実行使用メモリ | 54,420 KB |
| 最終ジャッジ日時 | 2024-10-04 22:33:26 |
| 合計ジャッジ時間 | 9,916 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
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;
}
}