結果

問題 No.966 引き算をして門松列(その1)
ユーザー htensaihtensai
提出日時 2020-01-16 11:53:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 1,245 bytes
コンパイル時間 2,727 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 60,468 KB
最終ジャッジ日時 2023-09-05 18:41:12
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,216 KB
testcase_01 AC 126 ms
55,520 KB
testcase_02 AC 127 ms
55,700 KB
testcase_03 AC 137 ms
53,512 KB
testcase_04 AC 308 ms
60,468 KB
testcase_05 AC 371 ms
60,204 KB
testcase_06 AC 409 ms
59,028 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();
            sb.append(getCount(a, b, c)).append("\n");
        }
        System.out.print(sb);
    }
    
    static int getCount(int a, int b, int c) {
        int min = Integer.MAX_VALUE;
        min = Math.min(min, getOrderCount(a, c, b));
        min = Math.min(min, getOrderCount(c, a, b));
        min = Math.min(min, getOrderCount(b, a, c));
        min = Math.min(min, getOrderCount(b, c, a));
        if (min == Integer.MAX_VALUE) {
            return -1;
        } else {
            return min;
        }
    }
    
    static int getOrderCount(int a, int b, int c) {
        int count = 0;
        if (a <= b) {
            count += b - a + 1;
            b = a - 1;
        }
        if (b <= c) {
            count += c - b + 1;
            c = b - 1;
        }
        if (c <= 0) {
            return Integer.MAX_VALUE;
        } else {
            return count;
        }
    }
}
0