結果
| 問題 |
No.968 引き算をして門松列(その3)
|
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-01-13 21:04:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 2,210 bytes |
| コンパイル時間 | 1,995 ms |
| コンパイル使用メモリ | 177,864 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-22 20:46:19 |
| 合計ジャッジ時間 | 2,820 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#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 (C >= A) {
res += (C-A+1LL)*Y;
B -= (C-A+1LL);
C = A-1LL;
}
if (A >= B) {
res += (A-B+1LL)*Z;
C -= (A-B+1LL);
A = B-1LL;
}
if (C <= 0) return 5e18;
return res;
}
ll f2(ll A, ll B, ll C) {
ll res = 0;
if (A >= C) {
res += (A-C+1LL)*X;
B -= (A-C+1LL);
A = C-1LL;
}
if (C >= B) {
res += (C-B+1LL)*Z;
A -= (C-B+1LL);
C = B-1LL;
}
if (A <= 0) return 5e18;
return res;
}
ll f3(ll A, ll B, ll C) {
ll res = 0;
if (B >= A) {
res += (B-A+1LL)*Y;
C -= (B-A+1LL);
B = A-1LL;
}
if (A >= C) {
res += (A-C+1LL)*X;
B -= (A-C+1LL);
A = C-1LL;
}
if (B <= 0) return 5e18;
return res;
}
ll f4(ll A, ll B, ll C) {
ll res = 0;
if (B >= C) {
res += (B-C+1LL)*X;
A -= (B-C+1LL);
B = C-1LL;
}
if (C >= A) {
res += (C-A+1LL)*Y;
B -= (C-A+1LL);
C = A-1LL;
}
if (B <= 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;
}
}
minato