結果
問題 |
No.966 引き算をして門松列(その1)
|
ユーザー |
|
提出日時 | 2021-06-25 23:38:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 997 bytes |
コンパイル時間 | 1,591 ms |
コンパイル使用メモリ | 166,096 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 07:46:14 |
合計ジャッジ時間 | 2,170 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair<int, int> ll calc(ll fi, ll se, ll th) { ll res = 0; if (se >= fi) { res += se-fi+1; se = fi-1; } if (se <= 1) return -1; if (th >= se) { res += th-se+1; } return res; } const ll INF = 1e18; int main() { int t; cin >> t; rep(ti, t) { ll a, b, c; cin >> a >> b >> c; ll ans = INF; bool flag = false; ll cand = INF; // case1 if (calc(b,a,c) != -1) { flag = true; cand = min(cand, calc(b,a,c)); }; // case2 if (calc(c,a,b) != -1) { flag = true; cand = min(cand, calc(c,a,b)); } // case3 if (calc(a,c,b) != -1) { flag = true; cand = min(cand, calc(a,c,b)); } // case4 if (calc(b,c,a) != -1) { flag = true; cand = min(cand, calc(b,c,a)); } if (flag) ans = cand; else ans = -1; cout << ans << endl; } }