結果

問題 No.966 引き算をして門松列(その1)
ユーザー kk
提出日時 2020-07-04 04:13:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 201,388 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 11:11:06
合計ジャッジ時間 2,999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 14 ms
4,348 KB
testcase_05 AC 15 ms
4,348 KB
testcase_06 AC 18 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
const int INF = numeric_limits<int>::max();

int solve() {
  int a, b, c;
  int at, bt, ct;

  cin >> a >> b >> c;

  int ret = INF;

  // b is max
  int x = 0;
  at = a, bt = b, ct = c;
  if (at >= bt) {
    x += at - bt + 1;
    at = bt - 1;
  }
  if (ct >= bt) {
    x += ct - bt + 1;
    ct = bt - 1;
  }
  if (at == ct) {
    ++x;
    --at;
  }
  if (at > 0 && bt > 0 && ct > 0)
    ret = min(ret, x);
  
  // b is min
  int y = 0;
  at = a, bt = b, ct = c;
  if (at == ct) {
    --at;
    ++y;
  }
  if (bt >= at) {
    y += bt - at + 1;
    bt = at - 1;
  }
  if (bt >= ct) {
    y += bt - ct + 1;
    bt = ct - 1;
  }
  if (at > 0 && bt > 0 && ct > 0)
    ret = min(ret, y);

  if (ret == INF)
    return -1;
  
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t;
  cin >> t;
  while (t--) {
    cout << solve() << endl;
  }
  return 0;
}
0