結果

問題 No.967 引き算をして門松列(その2)
ユーザー ks2mks2m
提出日時 2020-01-13 21:35:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 3,229 ms
コンパイル使用メモリ 73,856 KB
実行使用メモリ 57,068 KB
最終ジャッジ日時 2023-08-24 15:30:23
合計ジャッジ時間 6,413 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,412 KB
testcase_01 AC 42 ms
49,420 KB
testcase_02 AC 42 ms
49,408 KB
testcase_03 AC 198 ms
55,596 KB
testcase_04 AC 200 ms
55,884 KB
testcase_05 AC 213 ms
55,736 KB
testcase_06 AC 198 ms
55,428 KB
testcase_07 AC 196 ms
56,080 KB
testcase_08 AC 241 ms
56,148 KB
testcase_09 AC 263 ms
57,068 KB
testcase_10 AC 270 ms
57,036 KB
testcase_11 AC 280 ms
56,852 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 x = Integer.parseInt(sa[3]);
			long y = Integer.parseInt(sa[4]);
			long z = Integer.parseInt(sa[5]);

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

			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