結果

問題 No.555 世界史のレポート
ユーザー tentententen
提出日時 2023-12-19 09:29:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 2,250 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 84,384 KB
実行使用メモリ 56,040 KB
最終ジャッジ日時 2023-12-19 09:29:48
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
53,996 KB
testcase_01 AC 51 ms
53,996 KB
testcase_02 AC 50 ms
53,992 KB
testcase_03 AC 54 ms
53,992 KB
testcase_04 AC 50 ms
53,980 KB
testcase_05 AC 50 ms
53,988 KB
testcase_06 AC 51 ms
53,992 KB
testcase_07 AC 52 ms
53,992 KB
testcase_08 AC 53 ms
54,000 KB
testcase_09 AC 53 ms
54,004 KB
testcase_10 AC 172 ms
55,932 KB
testcase_11 AC 161 ms
55,912 KB
testcase_12 AC 153 ms
56,036 KB
testcase_13 AC 137 ms
55,928 KB
testcase_14 AC 155 ms
55,924 KB
testcase_15 AC 165 ms
55,920 KB
testcase_16 AC 149 ms
55,920 KB
testcase_17 AC 179 ms
56,012 KB
testcase_18 AC 159 ms
55,932 KB
testcase_19 AC 193 ms
56,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] dp;
    static int copy;
    static int paste;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        copy = sc.nextInt();
        paste = sc.nextInt();
        dp = new int[n * 2];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        dp[1] = 0;
        int ans = Integer.MAX_VALUE;
        for (int i = n; i < n * 2; i++) {
            ans = Math.min(ans, dfw(i));
        }
        System.out.println(ans);
    }
    
    static int dfw(int x) {
        if (dp[x] < 0) {
            dp[x] = copy + paste * (x - 1);
            for (int i = 2; i <= Math.sqrt(x); i++) {
                if (x % i == 0) {
                    dp[x] = Math.min(dp[x], dfw(x / i) + copy + paste * (i - 1));
                    dp[x] = Math.min(dp[x], dfw(i) + copy + paste * (x / i - 1));
                }
            }
        }
        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