結果
問題 | No.966 引き算をして門松列(その1) |
ユーザー | CuriousFairy315 |
提出日時 | 2020-01-13 20:39:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 494 ms / 2,000 ms |
コード長 | 1,591 bytes |
コンパイル時間 | 2,841 ms |
コンパイル使用メモリ | 74,212 KB |
実行使用メモリ | 61,244 KB |
最終ジャッジ日時 | 2023-08-23 13:10:47 |
合計ジャッジ時間 | 5,010 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
56,296 KB |
testcase_01 | AC | 121 ms
56,216 KB |
testcase_02 | AC | 126 ms
55,844 KB |
testcase_03 | AC | 135 ms
55,832 KB |
testcase_04 | AC | 408 ms
61,244 KB |
testcase_05 | AC | 422 ms
60,864 KB |
testcase_06 | AC | 494 ms
60,404 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(); int a, b, c; int INF = 2_000_000_000; int cost = INF; if (C > 1 && B > 2) { // 1. A<C<B b = B; c = Math.min(b - 1, C); a = Math.min(c - 1, A); cost = Math.min(cost, (A - a) + (B - b) + (C - c)); } if (A > 1 && B > 2) { // 2. C<A<B b = B; a = Math.min(b - 1, A); c = Math.min(a - 1, C); cost = Math.min(cost, (A - a) + (B - b) + (C - c)); } if (A > 1 && C > 2) { // 3. B<A<C c = C; a = Math.min(c - 1, A); b = Math.min(a - 1, B); cost = Math.min(cost, (A - a) + (B - b) + (C - c)); } if (C > 1 && A > 2) { // 4. B<C<A a = A; c = Math.min(a - 1, C); b = Math.min(c - 1, B); cost = Math.min(cost, (A - a) + (B - b) + (C - c)); } if (cost == INF) System.out.println(-1); else System.out.println(cost); } } } }