結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-28 16:53:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 2,095 bytes |
| コンパイル時間 | 1,634 ms |
| コンパイル使用メモリ | 172,236 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 13:43:43 |
| 合計ジャッジ時間 | 2,342 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
bool isKado(ll x, ll y, ll z) {
if (x == y || y == z || z == x)return false;
if (x <= 0 || y <= 0 || z <= 0)return false;
static ll a[3];
a[0] = x; a[1] = y; a[2] = z;
sort(a, a + 3);
return y != a[1];
}
void solve() {
int T;
cin >> T;
vi P{ 0,1,2 };
while (T--) {
ll A[3], X[3], U[3];
rep(i, 3) {
cin >> A[i];
}
cin >> X[2] >> X[0] >> X[1];
ll ans = LLONG_MAX;
do {
rep(i, 3) {
U[i] = A[i];
}
ll cost = 0;
// 二番目に高い=>一番高い
for (int i = 1; i >= 0; --i) {
ll maxi = LLONG_MIN;
int p = P[i];
FOR(j, i + 1, 3) {
int q = P[j];
smax(maxi, U[q]);
}
if (U[p] <= maxi) {
ll cuts = maxi - U[p] + 1;
rep(j, 3) {
if (j != i) {
int q = P[j];
U[q] -= cuts;
}
}
cost += cuts * X[p];
}
}
if (isKado(U[0], U[1], U[2])) {
smin(ans, cost);
}
} while (next_permutation(all(P)));
cout << (ans == LLONG_MAX ? -1 : ans) << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}