結果

問題 No.966 引き算をして門松列(その1)
ユーザー minatominato
提出日時 2020-01-13 20:46:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 173,012 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:22:42
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int f1(int A, int B, int C) {
    int res = 0;
    if (A>= B) {
        res += A-B+1;
        A = B-1;
    }
    if (C >= A) {
        res += C-A+1;
        C = A-1;
    }
    if (A <= 0 || C <= 0) return INF;
    return res;
}

int f2(int A, int B, int C) {
    int res = 0;
    if (C >= B) {
        res += C-B+1;
        C = B-1;
    }
    if (A >= C) {
        res += A-C+1;
        A = C-1;
    } 
    if (A <= 0 || C <= 0) return INF;
    return res;
}

int f3(int A, int B, int C) {
    int res = 0;
    if (A >= C) {
        res += A-C+1;
        A = C-1;
    }
    if (B >= A) {
        res += B-A+1;
        B = A-1;
    } 
    if (B <= 0 || A <= 0) return INF;
    return res;
}

int f4(int A, int B, int C) {
    int res = 0;
    if (C >= A) {
        res += C-A+1;
        C = A-1;
    }
    if (B >= C) {
        res += B-C+1;
        B = C-1;
    } 
    if (B <= 0 || C <= 0) return INF;
    return res;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T; cin >> T;
    while (T--) {
        int A,B,C; cin >> A >> B >> C;
        int ans = INF;
        chmin(ans,f1(A,B,C));
        chmin(ans,f2(A,B,C));
        chmin(ans,f3(A,B,C));
        chmin(ans,f4(A,B,C));
        if (ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
}
0