結果

問題 No.385 カップ麺生活
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-18 15:39:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 78,720 KB
実行使用メモリ 56,476 KB
最終ジャッジ日時 2024-04-09 19:51:49
合計ジャッジ時間 8,241 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 133 ms
54,132 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 124 ms
53,124 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 131 ms
54,176 KB
testcase_10 AC 151 ms
54,440 KB
testcase_11 AC 131 ms
54,248 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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[] c = new int[N];
    for(int i = 0; i < N; i++) {
      c[i] = sc.nextInt();
    }
    ArrayList<Integer> P = new ArrayList<Integer>();
    for(int i = 2; i < M; i++) {
      boolean flg = true;
      for(int j = 2; j * j <= i; j++) {
        if(i % j == 0) {
          flg = false;
          break;
        }
      }
      if(flg) P.add(i);
    }
    Arrays.sort(c);
    // dp[i]はちょうどi円購入したときの最大購入数を表す(不可能な場合は0)
    int[] dp = new int[M];
    for(int i = 1; i < M; i++) {
      for(int k = 0; k < N; k++) {
        if(i >= c[k]) dp[i] = Math.max(dp[i], dp[i - c[k]] + 1);
      }
    }
    int ans = 0;
    for(int i = 0; i < P.size(); i++) {
      ans += dp[M - P.get(i)];
    }
    ans += (M / c[0]);
    System.out.println(ans);
  }
}
0