結果

問題 No.967 引き算をして門松列(その2)
ユーザー uwiuwi
提出日時 2020-01-13 19:52:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 76,192 KB
実行使用メモリ 61,188 KB
最終ジャッジ日時 2023-08-23 12:30:15
合計ジャッジ時間 7,880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,712 KB
testcase_01 AC 119 ms
55,644 KB
testcase_02 AC 122 ms
55,520 KB
testcase_03 AC 250 ms
60,320 KB
testcase_04 AC 253 ms
60,360 KB
testcase_05 AC 252 ms
59,868 KB
testcase_06 AC 251 ms
59,832 KB
testcase_07 AC 272 ms
60,296 KB
testcase_08 AC 367 ms
61,068 KB
testcase_09 AC 350 ms
61,188 KB
testcase_10 AC 359 ms
61,132 KB
testcase_11 AC 362 ms
60,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class D {
	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++) {
			long A = ni(), B = ni(), C = ni();
			long X = ni(), Y = ni(), Z = 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();
			if(!(1 <= X && X <= 1000000000))throw new RuntimeException();
			if(!(1 <= Y && Y <= 1000000000))throw new RuntimeException();
			if(!(1 <= Z && Z <= 1000000000))throw new RuntimeException();
			long ans = Long.MAX_VALUE;
			ans = Math.min(ans, cost(C, A, B, Z, X, Y));
			ans = Math.min(ans, cost(A, C, B, X, Z, Y));
			ans = Math.min(ans, cost(B, A, C, Y, X, Z));
			ans = Math.min(ans, cost(B, C, A, Y, Z, X));
			out.println(ans == Long.MAX_VALUE ? -1 : ans);
		}
	}
	
	static long cost(long a, long b, long c, long x, long y, long z)
	{
		long ret = 0;
		if(b >= c) {
			ret += (b-c+1)*y;
			b = c-1;
		}
		if(a >= b) {
			ret += (a-b+1)*x;
			a = b-1;
		}
		if(a <= 0)return Long.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