結果

問題 No.966 引き算をして門松列(その1)
ユーザー hipopo
提出日時 2020-01-18 17:45:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 100,248 KB
最終ジャッジ日時 2025-01-08 20:07:20
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

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