結果

問題 No.967 引き算をして門松列(その2)
ユーザー drken1215drken1215
提出日時 2020-01-13 21:00:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 3,742 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 103,520 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-24 13:23:07
合計ジャッジ時間 3,133 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 17 ms
4,384 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 21 ms
4,380 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 25 ms
4,380 KB
testcase_08 AC 42 ms
4,388 KB
testcase_09 AC 43 ms
4,380 KB
testcase_10 AC 40 ms
4,384 KB
testcase_11 AC 45 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}


const long long INF = 1LL<<60;

bool isok(long long a, long long b, long long c) {
    if (a < 1 || b < 1 || c < 1) return false;
    if (a == b) return false;
    if (b == c) return false;
    if (c == a) return false;
    if (a < b && b < c) return false;
    if (a > b && b > c) return false;
    return true;
}

long long A, B, C, X, Y, Z;

long long solve() {
    if (isok(A, B, C)) return 0;
    
    long long mi = min(min(A, B), C);
    long long ma = max(max(A, B), C);

    if (ma - mi <= 5) {
        long long res = INF;
        for (int a = 0; a <= 10; ++a) {
            for (int b = 0; b <= 10; ++b) {
                for (int c = 0; c <= 10; ++c) {
                    if (isok(A-a, B-b, C-c)) {
                        chmin(res, (long long)(a*X + b*Y + c*Z));
                    }
                }
            }
        }
        if (res < INF) return res;
        else return -1;
    }
    else {
        long long res = INF;
        vector<long long> alt;
        for (int it = 0; it <= 2; ++it) {
            alt.push_back(A - it);
            alt.push_back(B - it);
            alt.push_back(C - it);
        }

        for (auto a : alt) {
            for (auto b : alt) {
                for (auto c : alt) {
                    if (A < a) continue;
                    if (B < b) continue;
                    if (C < c) continue;
                    if (isok(a, b, c)) {
                        chmin(res, (A - a) * X + (B - b) * Y + (C - c) * Z);
                    }
                }
            }
        }
        if (res < INF) return res;
        else return -1;
    }
}


int main() {
    int T; cin >> T;
    for (int _ = 0; _ < T; ++_) {
        cin >> A >> B >> C >> X >> Y >> Z;
        cout << solve() << endl;
    }
}













0