結果

問題 No.966 引き算をして門松列(その1)
ユーザー silviasetitechsilviasetitech
提出日時 2020-03-06 09:07:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,533 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 77,428 KB
実行使用メモリ 48,112 KB
最終ジャッジ日時 2024-04-22 03:45:54
合計ジャッジ時間 4,537 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
41,064 KB
testcase_01 AC 105 ms
41,340 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Kadomatsu solver = new Kadomatsu();
        solver.solve(1, in, out);
        out.close();
    }

    static class Kadomatsu {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            //
            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                out.println(query(in.nextInt(), in.nextInt(), in.nextInt()));
            }
        }

        private long query(int a, int b, int c) {
            long res = (long) 1e11;
            if (b < 3 && Math.min(a, c) == 1) {
                return -1;
            }
            int tmp = 0;
            if (a == c) {
                ++tmp;
                --c;
            }
            if (Math.min(a, c) >= 2) {
                res = Math.min(res, /* b が 最小になる*/ Math.max(0, tmp + b - Math.min(a, c) + 1));
            }
            if (b >= 3) {
                res = Math.min(res, /* b が 最大になる*/ Math.max(0, tmp + a - b + 1 + c - b + 2));
            }
            return res;
        }

    }
}

0