結果
問題 | No.968 引き算をして門松列(その3) |
ユーザー | CuriousFairy315 |
提出日時 | 2020-01-13 21:06:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 569 ms / 2,000 ms |
コード長 | 2,153 bytes |
コンパイル時間 | 4,760 ms |
コンパイル使用メモリ | 73,412 KB |
実行使用メモリ | 61,080 KB |
最終ジャッジ日時 | 2023-08-24 13:37:52 |
合計ジャッジ時間 | 7,553 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
55,560 KB |
testcase_01 | AC | 122 ms
55,704 KB |
testcase_02 | AC | 127 ms
55,868 KB |
testcase_03 | AC | 379 ms
60,960 KB |
testcase_04 | AC | 359 ms
60,820 KB |
testcase_05 | AC | 380 ms
60,440 KB |
testcase_06 | AC | 382 ms
60,336 KB |
testcase_07 | AC | 409 ms
61,080 KB |
testcase_08 | AC | 506 ms
60,872 KB |
testcase_09 | AC | 533 ms
60,920 KB |
testcase_10 | AC | 569 ms
60,824 KB |
testcase_11 | AC | 545 ms
60,468 KB |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { new Main(); } public Main() { try (Scanner sc = new Scanner(System.in)) { int T = sc.nextInt(); while((T--) > 0) { int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(); long X = sc.nextInt(), Y = sc.nextInt(), Z = sc.nextInt(); int a, b, c; long INF = 2_000_000_000_000_000_000L; long cost = INF; // 2つを引くのは1個を足すのに等しいが、構築可能判定が必要 { // 1. A<C<B a = A; c = Math.max(a + 1, C); b = Math.max(c + 1, B); if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 2. C<A<B c = C; a = Math.max(c + 1, A); b = Math.max(a + 1, B); if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 3. B<A<C b = B; a = Math.max(b + 1, A); c = Math.max(a + 1, C); if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } { // 4. B<C<A b = B; c = Math.max(b + 1, C); a = Math.max(c + 1, A); if (A > (b - B) + (c - C) && B > (a - A) + (c - C) && C > (a - A) + (b - B)) cost = Math.min(cost, Y * (a - A) + Z * (b - B) + X * (c - C)); } if (cost == INF) System.out.println(-1); else System.out.println(cost); } } } }