結果

問題 No.966 引き算をして門松列(その1)
ユーザー hipopohipopo
提出日時 2020-01-18 17:45:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 100,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 06:40:24
合計ジャッジ時間 1,599 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 21 ms
4,376 KB
testcase_06 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
const long long MOD = 1e9+7;

int main() { 
    int t;
    cin >> t;
    const int INF = 1e9+1;
    for (int _t = 0; _t < t; _t++) {
        int a, b, c;
        cin >> a >> b >> c;

        int min_cost = INF;
        if (b >= 3) {
            int na = a, nc = c;
            if (na >= b) na = b - 1;
            if (nc >= b) nc = b - 1;
            if (na == nc) {
                if (na == 1) {
                    na = -INF;
                    nc = -INF;
                }
                else na--;
            }
            chmin(min_cost, a - na + c - nc);
        }

        if (a < c) swap(a, c);
        int nb = b, nc = c;
        if (a == nc) {
            nc--;
        }
        if (nb >= nc) nb = nc - 1;
        if (1 <= nb && 1 <= nc) chmin(min_cost, b - nb + c - nc);

        cout << (min_cost == INF ? -1 : min_cost) << endl;
    }
}   
0