結果

問題 No.968 引き算をして門松列(その3)
ユーザー 👑 emthrmemthrm
提出日時 2020-01-13 22:18:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,927 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 192,848 KB
最終ジャッジ日時 2025-01-08 17:48:29
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
ll solve(ll a, ll b, ll c, ll x, ll y, ll z) {
ll cost = 0;
// cout << a << ' ' << b << ' ' << c << '\n';
if (a < b && b < c) return cost;
if (b >= c) {
int diff = b - (c - 1);
a -= diff;
b -= diff;
cost += x * diff;
}
if (a < 1 || b < 1) return LINF;
if (a < b) return cost;
int diff = a - (b - 1);
if (c - b - 1 < diff) {
int diff2 = diff - (c - b - 1);
cost += x * diff2;
a -= diff2;
b -= diff2;
}
a -= diff;
c -= diff;
cost += z * diff;
if (a < 1) return LINF;
return cost;
}
int main() {
int t; cin >> t;
while (t--) {
int a, b, c; ll x, y, z; cin >> a >> b >> c >> x >> y >> z;
ll ans = LINF;
chmin(ans, solve(b, c, a, y, z, x));
chmin(ans, solve(b, a, c, x, z, y));
chmin(ans, solve(c, a, b, z, x, y));
chmin(ans, solve(a, c, b, z, y, x));
cout << (ans == LINF ? -1 : ans) << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0