結果
問題 | No.966 引き算をして門松列(その1) |
ユーザー | mikianaaa |
提出日時 | 2020-09-04 11:59:26 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 1,239 bytes |
コンパイル時間 | 1,490 ms |
コンパイル使用メモリ | 168,084 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-16 16:49:58 |
合計ジャッジ時間 | 2,407 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 16 ms
4,376 KB |
testcase_05 | AC | 17 ms
4,380 KB |
testcase_06 | AC | 21 ms
4,376 KB |
ソースコード
#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; } }