結果

問題 No.555 世界史のレポート
ユーザー htensaihtensai
提出日時 2019-11-14 22:40:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 3,150 ms
コンパイル使用メモリ 77,036 KB
実行使用メモリ 41,848 KB
最終ジャッジ日時 2023-10-22 02:49:29
合計ジャッジ時間 7,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,000 KB
testcase_01 AC 114 ms
41,052 KB
testcase_02 AC 102 ms
41,144 KB
testcase_03 AC 120 ms
41,368 KB
testcase_04 AC 123 ms
41,116 KB
testcase_05 AC 113 ms
41,376 KB
testcase_06 AC 116 ms
41,160 KB
testcase_07 AC 118 ms
41,188 KB
testcase_08 AC 124 ms
41,156 KB
testcase_09 AC 114 ms
41,020 KB
testcase_10 AC 138 ms
41,720 KB
testcase_11 AC 132 ms
41,748 KB
testcase_12 AC 126 ms
41,664 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 126 ms
41,612 KB
testcase_16 AC 126 ms
41,676 KB
testcase_17 AC 123 ms
41,688 KB
testcase_18 AC 123 ms
41,716 KB
testcase_19 AC 125 ms
41,760 KB
権限があれば一括ダウンロードができます

ソースコード

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