結果

問題 No.968 引き算をして門松列(その3)
ユーザー ks2mks2m
提出日時 2020-01-13 21:51:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 5,863 ms
コンパイル使用メモリ 74,052 KB
実行使用メモリ 56,984 KB
最終ジャッジ日時 2023-08-24 16:14:20
合計ジャッジ時間 5,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,356 KB
testcase_01 AC 43 ms
49,344 KB
testcase_02 AC 43 ms
49,296 KB
testcase_03 AC 188 ms
55,136 KB
testcase_04 AC 197 ms
56,016 KB
testcase_05 AC 219 ms
55,484 KB
testcase_06 AC 207 ms
55,528 KB
testcase_07 AC 190 ms
55,872 KB
testcase_08 AC 241 ms
55,452 KB
testcase_09 AC 260 ms
56,664 KB
testcase_10 AC 272 ms
56,832 KB
testcase_11 AC 278 ms
56,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

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 ans = Long.MAX_VALUE;
			long[] v = new long[3];
			v[0] = b;
			v[1] = a;
			v[2] = c;
			long c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			long c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * z + c2 * y;
				ans = Math.min(ans, val);
			}

			v[0] = b;
			v[1] = c;
			v[2] = a;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * z + c2 * x;
				ans = Math.min(ans, val);
			}

			v[0] = a;
			v[1] = c;
			v[2] = b;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * y + c2 * x;
				ans = Math.min(ans, val);
			}

			v[0] = c;
			v[1] = a;
			v[2] = b;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * x + c2 * y;
				ans = Math.min(ans, val);
			}

			if (ans == Long.MAX_VALUE) {
				System.out.println(-1);
			} else {
				System.out.println(ans);
			}
		}
		br.close();
	}
}
0