結果

問題 No.967 引き算をして門松列(その2)
ユーザー uwiuwi
提出日時 2020-01-13 19:50:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,594 bytes
コンパイル時間 4,129 ms
コンパイル使用メモリ 75,560 KB
実行使用メモリ 65,072 KB
最終ジャッジ日時 2023-08-23 12:26:41
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,796 KB
testcase_01 AC 120 ms
55,852 KB
testcase_02 WA -
testcase_03 AC 254 ms
60,300 KB
testcase_04 AC 251 ms
60,208 KB
testcase_05 AC 258 ms
59,980 KB
testcase_06 AC 262 ms
60,508 KB
testcase_07 AC 277 ms
60,408 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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();
			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)
	{
		int 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