結果

問題 No.967 引き算をして門松列(その2)
ユーザー minatominato
提出日時 2020-01-13 20:54:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,055 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 174,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:39:41
合計ジャッジ時間 2,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 20 ms
4,380 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;
}
///////////////////////////////////////////////////////////////

ll X,Y,Z;

ll f1(ll A, ll B, ll C) {
    ll res = 0;
    if (A>= B) {
        res += (A-B+1LL)*X;
        A = B-1LL;
    }
    if (C >= A) {
        res += (C-A+1)*Z;
        C = A-1LL;
    }
    if (A <= 0 || C <= 0) return 5e18;
    return res;
}

ll f2(ll A, ll B, ll C) {
    ll res = 0;
    if (C >= B) {
        res += (C-B+1LL)*Z;
        C = B-1LL;
    }
    if (A >= C) {
        res += (A-C+1LL)*X;
        A = C-1LL;
    } 
    if (A <= 0 || C <= 0) return 5e18;
    return res;
}

ll f3(ll A, ll B, ll C) {
    ll res = 0;
    if (A >= C) {
        res += (A-C+1LL)*X;
        A = C-1LL;
    }
    if (B >= A) {
        res += (B-A+1LL)*Y;
        B = A-1LL;
    } 
    if (B <= 0 || A <= 0) return 5e18;
    return res;
}

ll f4(ll A, ll B, ll C) {
    ll res = 0;
    if (C >= A) {
        res += (C-A+1LL)*Z;
        C = A-1LL;
    }
    if (B >= C) {
        res += (B-C+1LL)*Y;
        B = C-1LL;
    } 
    if (B <= 0 || C <= 0) return 5e18;
    return res;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T; cin >> T;
    while (T--) {
        ll A,B,C; cin >> A >> B >> C >> X >> Y >> Z;
        ll ans = 5e18;
        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 == 5e18) cout << -1 << endl;
        else cout << ans << endl;
    }
}
0