結果

問題 No.966 引き算をして門松列(その1)
ユーザー tnakao0123tnakao0123
提出日時 2020-01-16 09:26:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 90,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 13:45:27
合計ジャッジ時間 1,365 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 966.cc:  No.966 引き算をして門松列(その1) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int INF = 1 << 30;

/* typedef */

/* global variables */

/* subroutines */

int check(int p, int q, int r) {
  int s = 0;
  int d0 = q - r + 1;
  if (d0 > 0) q -= d0, s += d0;
  int d1 = p - q + 1;
  if (d1 > 0) p -= d1, s += d1;

  return (p < 1 || q < 1 || r < 1) ? INF : s;
}

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int t;
  scanf("%d", &t);

  while (t--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    int mind = INF;
    setmin(mind, check(a, c, b));
    setmin(mind, check(c, a, b));
    setmin(mind, check(b, a, c));
    setmin(mind, check(b, c, a));

    printf("%d\n", (mind >= INF) ? -1 : mind);
  }
  return 0;
}
0