結果

問題 No.968 引き算をして門松列(その3)
ユーザー kotamanegikotamanegi
提出日時 2020-01-13 21:16:42
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 4,700 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 114,208 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 13:42:47
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas]
#pragma comment (linker, "/STACK:256000000")
                 ^
1 warning generated.

ソースコード

diff #

#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>

using namespace std;
typedef string::const_iterator State;
const long double Ma_PI = 3.1415926535897932384626433832795028841971L;
#define eps 1e-15L
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(100);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
typedef struct BigInt {
    string s = "0";
    BigInt operator +(BigInt obj) {
        string c;
        while (max(obj.s.length(), this->s.length()) + 1 > c.length()) {
            c.pb('0');
        }
        for (int q = 0; q < obj.s.length(); ++q) {
            c[c.length() - 1 - q] = obj.s[obj.s.length() - q - 1];
        }
        for (int q = 0; q < this->s.length(); ++q) {
            c[c.length() - 1 - q] += this->s[this->s.length() - 1 - q] - '0';
            if (c[c.length() - 1 - q] > '9') {
                c[c.length() - 2 - q]++;
                c[c.length() - 1 - q] -= 10;
            }
        }
        if (c.front() == '0') {
            c.erase(c.begin());
        }
        return BigInt{ c };
    }
    BigInt operator *(BigInt obj) {
        BigInt ans;
        for (int i = this->s.length() - 1; i >= 0; --i) {
            REP(q, this -> s[i] - '0') {
                ans = ans + obj;
            }
            obj.s.pb('0');
        }
        return ans;
    }
}BigInt;

#define int ll
void solve() {
    vector<int> inputs;
    vector<int> costs;
    REP(q, 3) {
        int a;
        cin >> a;
        inputs.pb(a);
    }
    REP(q, 3) {
        int a;
        cin >> a;
        costs.pb(a);
    }
    if (inputs[0] > inputs[2]||(inputs[0] == inputs[2]&&costs[0] > costs[1])) {
        swap(inputs[0], inputs[2]);
        swap(costs[0], costs[1]);
    }
    int ans = 0;
    if (inputs[0] == inputs[2]) {
        //take one X
        inputs[0]--;
        inputs[1]--;
        ans += costs[0];
        if (inputs[0] <= 0||inputs[1] <= 0) {
            cout << -1 << endl;
            return;
        }
    }
    if (inputs[0] != inputs[1] && inputs[1] != inputs[2] && inputs[0] != inputs[2]) {
        if (inputs[1] < min(inputs[0], inputs[2]) || inputs[1] > max(inputs[0], inputs[2])) {
            cout << ans << endl;
            return;
        }
    }
    //inputs[0] <= inputs[1] <= inputs[2]
    ll pre_ans = 5e18;
    {
        //take Z
        vector<int> tmp = inputs;
        int depth = tmp[2] - tmp[1] + 1;
        tmp[0] -= depth;
        tmp[2] -= depth;
        if (tmp[0] >= 1 && tmp[2] >= 1) {
            pre_ans = min(pre_ans, depth * costs[2]);
        }
    }
    {
        vector<int> tmp = inputs;
        int depth = tmp[1] - tmp[0] + 1;
        //take Y
        tmp[1] -= depth;
        tmp[2] -= depth;
        int cost = costs[1] * depth;
        if (tmp[1] == tmp[2]) {
            //take X
            tmp[0]--;
            tmp[1]--;
            cost += costs[0];
        }
        if (tmp[0] == tmp[2]) {
            tmp[1]--;
            int now_cost = 5e18;
            if (tmp[2] - 1 >= 1) {
                //take Y
                now_cost = min(now_cost, costs[1]);
            }
            if (tmp[0] - 1 >= 1) {
                //take X
                now_cost = min(now_cost, costs[0]);
            }
            cost += now_cost;
        }
        if (tmp[0] >= 1 && tmp[1] >= 1&&tmp[2] >= 1) {
            pre_ans = min(pre_ans, cost);
        }
    }
    if (pre_ans >= 5e18) {
        ans = -1;
    }
    else {
        ans += pre_ans;
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    int t;
    cin >> t;
    REP(tea,t)
    solve();
}
0