結果

問題 No.2009 Drunkers' Contest
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-07-15 22:20:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,259 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 76,532 KB
実行使用メモリ 79,632 KB
最終ジャッジ日時 2023-09-10 02:38:05
合計ジャッジ時間 45,423 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,800 KB
testcase_01 AC 127 ms
55,772 KB
testcase_02 AC 127 ms
55,740 KB
testcase_03 AC 128 ms
55,804 KB
testcase_04 AC 127 ms
55,824 KB
testcase_05 AC 126 ms
55,760 KB
testcase_06 AC 127 ms
55,724 KB
testcase_07 AC 127 ms
56,216 KB
testcase_08 AC 127 ms
56,112 KB
testcase_09 AC 127 ms
55,928 KB
testcase_10 AC 126 ms
55,904 KB
testcase_11 AC 128 ms
55,868 KB
testcase_12 AC 131 ms
55,824 KB
testcase_13 AC 132 ms
56,108 KB
testcase_14 AC 222 ms
58,944 KB
testcase_15 AC 223 ms
58,836 KB
testcase_16 AC 232 ms
59,248 KB
testcase_17 AC 246 ms
59,384 KB
testcase_18 AC 245 ms
59,008 KB
testcase_19 AC 253 ms
59,796 KB
testcase_20 AC 261 ms
59,972 KB
testcase_21 AC 263 ms
60,272 KB
testcase_22 AC 268 ms
60,268 KB
testcase_23 AC 268 ms
60,400 KB
testcase_24 AC 1,003 ms
67,384 KB
testcase_25 AC 1,051 ms
66,676 KB
testcase_26 AC 1,060 ms
66,740 KB
testcase_27 AC 1,014 ms
66,988 KB
testcase_28 AC 1,039 ms
66,480 KB
testcase_29 AC 1,052 ms
66,660 KB
testcase_30 AC 1,070 ms
66,688 KB
testcase_31 AC 1,059 ms
66,572 KB
testcase_32 AC 1,028 ms
66,916 KB
testcase_33 AC 1,017 ms
66,804 KB
testcase_34 AC 1,016 ms
66,868 KB
testcase_35 AC 1,045 ms
66,828 KB
testcase_36 AC 986 ms
67,292 KB
testcase_37 AC 1,059 ms
66,800 KB
testcase_38 AC 987 ms
66,496 KB
testcase_39 AC 1,052 ms
67,028 KB
testcase_40 AC 1,035 ms
66,676 KB
testcase_41 AC 991 ms
67,232 KB
testcase_42 AC 1,036 ms
66,736 KB
testcase_43 AC 1,028 ms
67,048 KB
testcase_44 AC 1,072 ms
74,124 KB
testcase_45 AC 1,080 ms
79,632 KB
testcase_46 AC 1,182 ms
75,116 KB
testcase_47 AC 922 ms
73,648 KB
testcase_48 AC 957 ms
74,452 KB
testcase_49 AC 886 ms
75,896 KB
testcase_50 AC 904 ms
75,036 KB
testcase_51 AC 923 ms
73,008 KB
testcase_52 AC 954 ms
74,004 KB
testcase_53 AC 1,106 ms
73,856 KB
testcase_54 AC 986 ms
71,568 KB
testcase_55 AC 1,259 ms
73,092 KB
testcase_56 AC 1,178 ms
67,308 KB
testcase_57 AC 980 ms
72,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


import static java.lang.System.err;
import static java.lang.System.out;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		new Main();
		out.flush();
		err.flush();
	}

	static class Pair {
		double A, B;
		double min;
		double score;
		Pair(double A, double B) {
			this.A = A;
			this.B = B;
			min = Math.max(0, Math.sqrt(A / B) - 1);
			score = A / (min + 1) + B * (min + 1);
		}
		@Override
		public String toString() {
			return "(" + A + ", " + B + ", " + min + ", " + score + ")";
		}
	}

	/**
	 * @author 31536000(@CuriousFairy315)
	 */
	public Main() {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int N = sc.nextInt();
			long[] A = new long[N], B = new long[N];
			for (int i = 0;i < N;++ i) A[i] = sc.nextInt();
			for (int i = 0;i < N;++ i) B[i] = sc.nextInt();
			ArrayDeque<Pair> stack = new ArrayDeque<>();
			for (int i = N - 1;i >= 0;-- i) {
				Pair push = new Pair(A[i], B[i]);
				while (!stack.isEmpty() && stack.peekLast().min < push.min) {
					Pair pop = stack.pollLast();
					push = new Pair(push.A + pop.A, push.B + pop.B);
				}
				stack.add(push);
//				out.println(stack);
			}
			double ans = 0;
			for (Pair p : stack) ans += p.score;
			out.println(ans);
		}
	}
}
0