結果

問題 No.967 引き算をして門松列(その2)
ユーザー htensaihtensai
提出日時 2020-01-16 11:59:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 62,108 KB
最終ジャッジ日時 2023-09-05 18:50:33
合計ジャッジ時間 7,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,000 KB
testcase_01 AC 123 ms
55,844 KB
testcase_02 AC 128 ms
55,800 KB
testcase_03 AC 285 ms
62,108 KB
testcase_04 AC 305 ms
60,388 KB
testcase_05 AC 295 ms
60,252 KB
testcase_06 AC 316 ms
60,412 KB
testcase_07 AC 337 ms
60,312 KB
testcase_08 AC 439 ms
60,684 KB
testcase_09 AC 460 ms
61,124 KB
testcase_10 AC 465 ms
60,416 KB
testcase_11 AC 463 ms
60,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int z = sc.nextInt();
            sb.append(getCount(a, x, b, y, c, z)).append("\n");
        }
        System.out.print(sb);
    }
    
    static long getCount(long a, long x, long b, long y, long c, long z) {
        long min = Long.MAX_VALUE;
        min = Math.min(min, getOrderCount(a, x, c, z, b, y));
        min = Math.min(min, getOrderCount(c, z, a, x, b, y));
        min = Math.min(min, getOrderCount(b, y, a, x, c, z));
        min = Math.min(min, getOrderCount(b, y, c, z, a, x));
        if (min == Long.MAX_VALUE) {
            return -1;
        } else {
            return min;
        }
    }
    
    static long getOrderCount(long a, long x, long b, long y, long c, long z) {
        long count = 0;
        if (a <= b) {
            count += (b - a + 1) * y;
            b = a - 1;
        }
        if (b <= c) {
            count += (c - b + 1) * z;
            c = b - 1;
        }
        if (c <= 0) {
            return Long.MAX_VALUE;
        } else {
            return count;
        }
    }
}
0