結果
問題 | No.968 引き算をして門松列(その3) |
ユーザー |
|
提出日時 | 2020-01-13 21:47:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 434 ms / 2,000 ms |
コード長 | 1,491 bytes |
コンパイル時間 | 1,851 ms |
コンパイル使用メモリ | 176,272 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-23 00:16:11 |
合計ジャッジ時間 | 4,989 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;const ll INF = 1e18;ll calc(vector<ll>& a, vector<ll>& b, vector<ll>& c) {ll res = 0;vector<ll> d = a;for (int i = 0; i < 3; ++i) {ll cnt = c[i] - a[i];if (cnt < 0) return INF;for (int j = 0; j < 3; ++j) {if (i == j) continue;d[j] -= cnt;}res += b[i] * cnt;}for (int i = 0; i < 3; ++i) {if (d[i] <= 0) return INF;}vector<ll> e = d;sort(e.begin(), e.end());if (e[0] == e[1] || e[1] == e[2]) return INF;if (d[1] == e[0] || d[1] == e[2]) return res;else return INF;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int t;cin >> t;for (int lo = 0; lo < t; ++lo) {vector<ll> a(3);vector<ll> b(3);for (int i = 0; i < 3; ++i) {cin >> a[i];}for (int i : {2, 0, 1}) {cin >> b[i];}vector<ll> v;for (int i = 0; i < 3; ++i) {v.push_back(a[i]);v.push_back(a[i] + 1);v.push_back(a[i] + 2);}ll ans = INF;for (ll i : v) {for (ll j : v) {for (ll k : v) {vector<ll> c = {i, j, k};ans = min(ans, calc(a, b, c));}}}cout << (ans >= INF ? -1 : ans) << "\n";}return 0;}