結果

問題 No.385 カップ麺生活
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-18 15:44:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 79,420 KB
実行使用メモリ 54,668 KB
最終ジャッジ日時 2024-04-15 07:38:43
合計ジャッジ時間 8,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
53,824 KB
testcase_01 AC 133 ms
54,508 KB
testcase_02 AC 134 ms
54,240 KB
testcase_03 AC 134 ms
54,416 KB
testcase_04 AC 135 ms
53,972 KB
testcase_05 AC 132 ms
53,928 KB
testcase_06 AC 124 ms
53,088 KB
testcase_07 AC 140 ms
54,156 KB
testcase_08 AC 134 ms
54,488 KB
testcase_09 AC 130 ms
54,232 KB
testcase_10 AC 153 ms
53,980 KB
testcase_11 AC 133 ms
54,088 KB
testcase_12 AC 138 ms
54,304 KB
testcase_13 AC 145 ms
53,940 KB
testcase_14 AC 151 ms
54,364 KB
testcase_15 AC 143 ms
54,300 KB
testcase_16 AC 134 ms
54,472 KB
testcase_17 AC 144 ms
54,476 KB
testcase_18 AC 136 ms
54,312 KB
testcase_19 AC 133 ms
54,172 KB
testcase_20 AC 143 ms
54,244 KB
testcase_21 AC 151 ms
54,356 KB
testcase_22 AC 143 ms
54,520 KB
testcase_23 AC 149 ms
54,516 KB
testcase_24 AC 141 ms
54,592 KB
testcase_25 AC 132 ms
54,276 KB
testcase_26 AC 139 ms
54,168 KB
testcase_27 AC 142 ms
54,668 KB
testcase_28 AC 158 ms
54,300 KB
testcase_29 AC 136 ms
54,012 KB
testcase_30 AC 150 ms
54,256 KB
testcase_31 AC 132 ms
54,352 KB
testcase_32 AC 133 ms
54,564 KB
testcase_33 AC 142 ms
54,136 KB
testcase_34 AC 135 ms
54,332 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[] 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]) {
          if(i == c[k]) {
            dp[i] = Math.max(dp[i], 1);
          } else {
            if(dp[i - c[k]] > 0) dp[i] = Math.max(dp[i], 1 + dp[i - c[k]]); 
          }
        }
      }
    }
    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