結果

問題 No.385 カップ麺生活
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-18 15:19:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 79,400 KB
実行使用メモリ 56,200 KB
最終ジャッジ日時 2024-04-09 19:48:48
合計ジャッジ時間 7,348 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 117 ms
54,204 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 128 ms
54,028 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 108 ms
53,984 KB
testcase_10 AC 135 ms
53,872 KB
testcase_11 AC 106 ms
54,100 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 AC 111 ms
54,400 KB
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][j]はカップ麺0~iからちょうどj円購入したときの最大購入数を表す(不可能な場合は0)
    int[][] dp = new int[N][M];
    for(int j = 1; j < M; j++) {
      if(j % c[0] == 0) dp[0][j] = j / c[0]; 
    }
    for(int i = 1; i < N; i++) {
      for(int j = 1; j < M; j++) {
        for(int k = 0; k <= i; k++) {
          if(j >= c[k]) dp[i][j] = Math.max(dp[i][j], dp[i][j - c[k]] + 1);
        }
      }
    }
    int ans = 0;
    for(int i = 0; i < P.size(); i++) {
      ans += dp[N - 1][M - P.get(i)];
    }
    ans += M / c[0];
    System.out.println(ans);
  }
}
0