結果

問題 No.555 世界史のレポート
ユーザー tentententen
提出日時 2023-06-14 16:24:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 2,201 bytes
コンパイル時間 4,565 ms
コンパイル使用メモリ 81,492 KB
実行使用メモリ 52,148 KB
最終ジャッジ日時 2023-09-05 03:51:03
合計ジャッジ時間 7,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,316 KB
testcase_01 AC 45 ms
49,196 KB
testcase_02 AC 44 ms
49,852 KB
testcase_03 AC 45 ms
49,188 KB
testcase_04 AC 48 ms
49,408 KB
testcase_05 AC 44 ms
49,424 KB
testcase_06 AC 46 ms
49,304 KB
testcase_07 AC 47 ms
49,332 KB
testcase_08 AC 46 ms
49,408 KB
testcase_09 AC 51 ms
49,308 KB
testcase_10 AC 139 ms
51,580 KB
testcase_11 AC 150 ms
51,604 KB
testcase_12 AC 140 ms
51,956 KB
testcase_13 AC 132 ms
51,548 KB
testcase_14 AC 148 ms
52,092 KB
testcase_15 AC 154 ms
51,884 KB
testcase_16 AC 132 ms
51,720 KB
testcase_17 AC 142 ms
52,148 KB
testcase_18 AC 151 ms
51,568 KB
testcase_19 AC 179 ms
51,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int c;
    static int v;
    static int[] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        c = sc.nextInt();
        v = sc.nextInt();
        dp = new int[n * 2];
        Arrays.fill(dp, -1);
        dp[1] = 0;
        int ans = Integer.MAX_VALUE;
        for (int i = n * 2 - 1; i >= n; i--) {
            ans = Math.min(ans, dfw(i));
        }
        System.out.println(ans);
    }
    
    static int dfw(int x) {
        if (dp[x] < 0) {
            dp[x] = c + v * (x - 1);
            for (int i = 2; i <= Math.sqrt(x); i++) {
                if (x % i == 0) {
                    dp[x] = Math.min(dp[x], dfw(i) + c + (x / i - 1) * v);
                    dp[x] = Math.min(dp[x], dfw(x / i) + c + (i - 1) * v);
                }
            }
        }
        return dp[x];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0