結果

問題 No.967 引き算をして門松列(その2)
ユーザー CuriousFairy315CuriousFairy315
提出日時 2020-01-13 20:42:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 570 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 71,488 KB
実行使用メモリ 61,272 KB
最終ジャッジ日時 2023-08-23 13:14:03
合計ジャッジ時間 7,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,892 KB
testcase_01 AC 127 ms
55,448 KB
testcase_02 AC 132 ms
55,724 KB
testcase_03 AC 362 ms
60,700 KB
testcase_04 AC 362 ms
60,384 KB
testcase_05 AC 372 ms
61,272 KB
testcase_06 AC 387 ms
60,616 KB
testcase_07 AC 422 ms
60,808 KB
testcase_08 AC 518 ms
60,736 KB
testcase_09 AC 540 ms
60,892 KB
testcase_10 AC 570 ms
60,924 KB
testcase_11 AC 544 ms
61,244 KB
権限があれば一括ダウンロードができます

ソースコード

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;
                if (C > 1 && B > 2) { // 1. A<C<B
                    b = B;
                    c = Math.min(b - 1, C);
                    a = Math.min(c - 1, A);
                    cost = Math.min(cost, X * (A - a) + Y * (B - b) + Z * (C - c));
                }
                if (A > 1 && B > 2) { // 2. C<A<B
                    b = B;
                    a = Math.min(b - 1, A);
                    c = Math.min(a - 1, C);
                    cost = Math.min(cost, X * (A - a) + Y * (B - b) + Z * (C - c));
                }
                if (A > 1 && C > 2) { // 3. B<A<C
                    c = C;
                    a = Math.min(c - 1, A);
                    b = Math.min(a - 1, B);
                    cost = Math.min(cost, X * (A - a) + Y * (B - b) + Z * (C - c));
                }
                if (C > 1 && A > 2) { // 4. B<C<A
                    a = A;
                    c = Math.min(a - 1, C);
                    b = Math.min(c - 1, 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