結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-04 11:59:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,239 bytes |
| コンパイル時間 | 1,337 ms |
| コンパイル使用メモリ | 171,024 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-25 06:22:53 |
| 合計ジャッジ時間 | 2,085 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int T;
cin >> T;
rep(i, T) {
int ans = 1e9;
vector<int> A(3), v;
rep(i, 3) {
cin >> A[i];
v.push_back(i);
}
do {
// A > B > Cみたいな感じで並べる。
// でかい順に並べるため中間にBがきてはならない(Bは最大か最小)
if (v[1] == 1)
continue;
// 最大は操作しない
int pre = A[v[0]];
int cost = 0;
for (int i = 1; i < 3; i++) {
int nxt = min(A[v[i]], pre - 1);
cost += A[v[i]] - nxt;
pre = nxt;
}
if (0 < pre) // 0いかはだめ。
ans = min(ans, cost);
} while (next_permutation(all(v)));
if (ans == 1e9)
cout << -1 << endl;
else
cout << ans << endl;
}
}