結果

問題 No.968 引き算をして門松列(その3)
ユーザー htensaihtensai
提出日時 2020-01-16 12:03:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,561 bytes
コンパイル時間 3,299 ms
コンパイル使用メモリ 79,176 KB
実行使用メモリ 60,608 KB
最終ジャッジ日時 2023-09-05 18:58:43
合計ジャッジ時間 8,133 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,884 KB
testcase_01 AC 125 ms
55,792 KB
testcase_02 AC 130 ms
55,920 KB
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.*;

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 (b <= c) {
            count += (c - b + 1) * z;
            long sa = c - b + 1;
            c = b - 1;
            a -= sa;
        }
        if (a <= b) {
            count += (b - a + 1) * y;
            long sa = b - a + 1;
            b = a - 1;
            c -= sa;
        }
        if (c <= 0) {
            return Long.MAX_VALUE;
        } else {
            return count;
        }
    }
}
0