結果

問題 No.555 世界史のレポート
ユーザー htensai
提出日時 2019-11-14 22:40:43
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 77,764 KB
実行使用メモリ 54,592 KB
最終ジャッジ日時 2024-09-22 04:22:45
合計ジャッジ時間 5,646 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int v = sc.nextInt();
		long[] dp = new long[n + 1];
		int[] counts = new int[n + 1];
		dp[1] = 0;
		counts[1] = 0;
		dp[2] = c + v;
		counts[2] = 1;
		for (int i = 3; i <= n; i++) {
		    long aValue = dp[(i + 1) / 2] + c + v;
		    int aCount = (i + 1) / 2;
		    int left = 1;
		    int right = i - 1;
		    while (right - left > 1) {
		        int m = (left + right) / 2;
		        if (m + counts[m] >= i) {
		            right = m;
		        } else {
		            left = m;
		        }
		    }
		    long bValue = dp[right] + v;
		    int bCount = counts[right];
		    if (aValue <= bValue) {
		        dp[i] = aValue;
		        counts[i] = aCount;
		    } else {
		        dp[i] = bValue;
		        counts[i] = bCount;
		    }
		}
		System.out.println(dp[n]);
	}
}
0