結果

問題 No.555 世界史のレポート
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-12 16:02:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 77,172 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2024-04-21 06:16:34
合計ジャッジ時間 5,934 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,000 KB
testcase_01 AC 111 ms
39,912 KB
testcase_02 AC 113 ms
40,676 KB
testcase_03 AC 116 ms
41,024 KB
testcase_04 AC 113 ms
39,636 KB
testcase_05 AC 111 ms
40,188 KB
testcase_06 AC 112 ms
40,980 KB
testcase_07 AC 120 ms
40,576 KB
testcase_08 AC 109 ms
41,032 KB
testcase_09 AC 114 ms
39,920 KB
testcase_10 AC 185 ms
40,420 KB
testcase_11 AC 206 ms
41,164 KB
testcase_12 AC 192 ms
41,248 KB
testcase_13 AC 172 ms
41,576 KB
testcase_14 AC 201 ms
41,288 KB
testcase_15 AC 197 ms
41,248 KB
testcase_16 AC 185 ms
41,252 KB
testcase_17 AC 197 ms
41,592 KB
testcase_18 AC 197 ms
41,260 KB
testcase_19 AC 233 ms
41,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c = sc.nextInt();
    int v = sc.nextInt();
    int[] dp = new int[2 * n - 1];
    dp[1] = 0;
    dp[2] = c + v;
    for(int i = 3; i < 2 * n - 1; i++) {
      int a = Integer.MAX_VALUE;
      a = Math.min(a, c + v * (i - 1)); 
      for(int j = 2; j * j <= i; j++) {
        if(i % j == 0) {
          a = Math.min(a, dp[j] + c + v * ((i - j) / j));
          int b = i / j;
          a = Math.min(a, dp[b] + c + v * ((i - b) / b));
        }
      }
      dp[i] = a;
    }
    int ans = Integer.MAX_VALUE;
    for(int i = n; i < 2 * n - 1; i++) {
      ans = Math.min(ans, dp[i]);
    }
    System.out.println(ans);
  }
}
0