結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-28 16:59:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 1,892 bytes |
| コンパイル時間 | 1,764 ms |
| コンパイル使用メモリ | 171,448 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 13:44:03 |
| 合計ジャッジ時間 | 2,417 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#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], U[3];
rep(i, 3) {
cin >> A[i];
}
ll ans = LLONG_MAX;
do {
rep(i, 3) {
U[i] = A[i];
}
ll cost = 0;
// 二番目に低い=>一番低い
for (int i = 1; i >= 0; --i) {
ll mini = LLONG_MAX;
int p = P[i];
FOR(j, i + 1, 3) {
int q = P[j];
smin(mini, U[q]);
}
if (U[p] >= mini) {
ll cuts = U[p] - mini + 1;
U[p] -= cuts;
cost += cuts;
}
}
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;
}