結果

問題 No.966 引き算をして門松列(その1)
ユーザー ks2mks2m
提出日時 2020-01-13 21:33:04
言語 Java19
(openjdk 21)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 3,508 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 55,784 KB
最終ジャッジ日時 2023-08-24 15:24:57
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
47,540 KB
testcase_01 AC 43 ms
49,540 KB
testcase_02 AC 43 ms
49,460 KB
testcase_03 AC 46 ms
49,332 KB
testcase_04 AC 236 ms
55,784 KB
testcase_05 AC 245 ms
55,508 KB
testcase_06 AC 267 ms
55,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		for (int i = 0; i < t; i++) {
			String[] sa = br.readLine().split(" ");
			long a = Integer.parseInt(sa[0]);
			long b = Integer.parseInt(sa[1]);
			long c = Integer.parseInt(sa[2]);

			long[] val = new long[4];
			Arrays.fill(val, Long.MAX_VALUE);
			if (b >= 3 && a >= 2) {
				val[0] = Math.max(a - (b - 1), 0) + Math.max(c - Math.min(a - 1, b - 2), 0);
			}
			if (b >= 3 && c >= 2) {
				val[1] = Math.max(c - (b - 1), 0) + Math.max(a - Math.min(c - 1, b - 2), 0);
			}
			if (a >= 3 && c >= 2) {
				val[2] = Math.max(c - (a - 1), 0) + Math.max(b - Math.min(c - 1, a - 2), 0);
			}
			if (c >= 3 && a >= 2) {
				val[3] = Math.max(a - (c - 1), 0) + Math.max(b - Math.min(a - 1, c - 2), 0);
			}

			long ans = Long.MAX_VALUE;
			for (int j = 0; j < val.length; j++) {
				ans = Math.min(ans, val[j]);
			}
			if (ans == Long.MAX_VALUE) {
				System.out.println(-1);
			} else {
				System.out.println(ans);
			}
		}
		br.close();
	}
}
0