結果

問題 No.966 引き算をして門松列(その1)
ユーザー uwiuwi
提出日時 2020-01-13 19:42:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 1,491 bytes
コンパイル時間 3,906 ms
コンパイル使用メモリ 75,024 KB
実行使用メモリ 61,996 KB
最終ジャッジ日時 2023-08-23 12:10:56
合計ジャッジ時間 5,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,692 KB
testcase_01 AC 118 ms
55,764 KB
testcase_02 AC 120 ms
55,696 KB
testcase_03 AC 123 ms
56,000 KB
testcase_04 AC 257 ms
60,256 KB
testcase_05 AC 291 ms
60,704 KB
testcase_06 AC 345 ms
61,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package contest200113;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class C {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int T = ni();
		if(!(1 <= T && T <= 10000))throw new RuntimeException();
		for(int i = 0;i < T;i++) {
			int A = ni(), B = ni(), C = ni();
			if(!(1 <= A && A <= 1000000000))throw new RuntimeException();
			if(!(1 <= B && B <= 1000000000))throw new RuntimeException();
			if(!(1 <= C && C <= 1000000000))throw new RuntimeException();
			int ans = Integer.MAX_VALUE;
			ans = Math.min(ans, cost(C, A, B));
			ans = Math.min(ans, cost(A, C, B));
			ans = Math.min(ans, cost(B, A, C));
			ans = Math.min(ans, cost(B, C, A));
			out.println(ans == Integer.MAX_VALUE ? -1 : ans);
		}
	}
	
	static int cost(int a, int b, int c)
	{
		int ret = 0;
		if(b >= c) {
			ret += b-c+1;
			b = c-1;
		}
		if(a >= b) {
			ret += a-b+1;
			a = b-1;
		}
		if(a <= 0)return Integer.MAX_VALUE;
		return ret;
	}
	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0