結果

問題 No.966 引き算をして門松列(その1)
ユーザー bonKotsubonKotsu
提出日時 2021-06-25 23:38:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 164,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 13:40:04
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 22 ms
4,376 KB
testcase_06 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }


}
0