結果

問題 No.555 世界史のレポート
ユーザー tenten
提出日時 2021-11-12 09:25:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 1,632 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 77,608 KB
実行使用メモリ 38,788 KB
最終ジャッジ日時 2024-11-24 15:59:16
合計ジャッジ時間 5,555 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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();
        int c = sc.nextInt();
        int v = sc.nextInt();
        int[] dp = new int[n * 2];
        int ans = Integer.MAX_VALUE;
        for (int i = 2; i < n * 2; i++) {
            dp[i] = c + v * (i - 1);
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    dp[i] = Math.min(dp[i], dp[j] + c + v * (i / j - 1));
                    dp[i] = Math.min(dp[i], dp[i / j] + c + v * (j - 1));
                }
            }
            if (i >= n) {
                ans = Math.min(ans, dp[i]);
            }
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0