結果

問題 No.968 引き算をして門松列(その3)
ユーザー CuriousFairy315CuriousFairy315
提出日時 2020-01-13 20:51:58
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,237 bytes
コンパイル時間 4,318 ms
コンパイル使用メモリ 78,876 KB
実行使用メモリ 63,116 KB
最終ジャッジ日時 2023-08-23 13:34:20
合計ジャッジ時間 8,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,972 KB
testcase_01 AC 124 ms
55,700 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main();
    }
    
    public Main() {
        try (Scanner sc = new Scanner(System.in)) {
            int T = sc.nextInt();
            while((T--) > 0) {
                int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
                long X = sc.nextInt(), Y = sc.nextInt(), Z = sc.nextInt();
                int a, b, c;
                long INF = 2_000_000_000_000_000_000L;
                long cost = INF;
                    // 2つを引くのは1個を足すのに等しいが、構築可能判定が必要
                if (C > 1 && B > 2) { // 1. A<C<B
                    a = A;
                    c = Math.max(a + 1, C);
                    b = Math.max(c + 1, B);
                    if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B))
                        cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C));
                }
                if (A > 1 && B > 2) { // 2. C<A<B
                    c = C;
                    a = Math.max(c + 1, A);
                    b = Math.max(a + 1, B);
                    if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B))
                        cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C));
                }
                if (A > 1 && C > 2) { // 3. B<A<C
                    b = B;
                    a = Math.max(b + 1, A);
                    c = Math.max(a + 1, C);
                    if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B))
                        cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C));
                }
                if (C > 1 && A > 2) { // 4. B<C<A
                    b = B;
                    c = Math.max(b + 1, C);
                    a = Math.max(c + 1, A);
                    if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B))
                        cost = Math.min(cost, X * (a - A) + Y * (b - B) + Z * (c - C));
                }
                if (cost == INF) System.out.println(-1);
                else System.out.println(cost);
            }
        }
    }
}
0