結果

問題 No.555 世界史のレポート
ユーザー GrenacheGrenache
提出日時 2017-08-11 22:52:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,203 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 3,818 ms
コンパイル使用メモリ 80,248 KB
実行使用メモリ 109,160 KB
最終ジャッジ日時 2024-04-20 23:10:43
合計ジャッジ時間 11,255 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
52,784 KB
testcase_01 AC 124 ms
54,096 KB
testcase_02 AC 104 ms
53,804 KB
testcase_03 AC 126 ms
54,136 KB
testcase_04 AC 135 ms
53,744 KB
testcase_05 AC 129 ms
54,204 KB
testcase_06 AC 126 ms
53,444 KB
testcase_07 AC 137 ms
54,548 KB
testcase_08 AC 118 ms
53,320 KB
testcase_09 AC 141 ms
54,244 KB
testcase_10 AC 561 ms
77,024 KB
testcase_11 AC 483 ms
75,364 KB
testcase_12 AC 766 ms
98,980 KB
testcase_13 AC 961 ms
99,108 KB
testcase_14 AC 1,203 ms
109,160 KB
testcase_15 AC 241 ms
58,384 KB
testcase_16 AC 457 ms
75,312 KB
testcase_17 AC 264 ms
62,900 KB
testcase_18 AC 508 ms
74,936 KB
testcase_19 AC 536 ms
76,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


public class Main_yukicoder555 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int c = sc.nextInt();
		int v = sc.nextInt();

		int min = c + v * (n - 1);

		PriorityQueue<Tuple> pq = new PriorityQueue<>();
		pq.add(new Tuple(2, 1, c + v));
		while (!pq.isEmpty()) {
			Tuple e = pq.remove();

			if (e.a >= n) {
				min = Math.min(min, e.c);
				continue;
			}
			if (e.c >= min) {
				continue;
			}

			pq.add(new Tuple(2 * e.a, e.a, e.c + c + v));
			pq.add(new Tuple(e.a + e.b, e.b, e.c + v));
		}

		pr.println(min);
	}

	private static class Tuple implements Comparable<Tuple> {
		int a; // length
		int b; // clip
		int c; // cost

		Tuple(int a, int b, int c) {
			this.a = a;
			this.b = b;
			this.c = c;
		}

		@Override
		public int compareTo(Tuple o) {
			if (c == o.c) {
				return Integer.compare(a, o.a);
			}

			return Integer.compare(c, o.c);
		}

		@Override
		public int hashCode() {
			return Integer.hashCode(a);
		}

		@Override
		public String toString() {
			// [xxx, xxxx]
			StringBuilder stmp = new StringBuilder(32);
			stmp.append('[');
			stmp.append(a);
			stmp.append(',');
			stmp.append(' ');
			stmp.append(b);
			stmp.append(']');

			return stmp.toString();
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0