結果

問題 No.966 引き算をして門松列(その1)
ユーザー ngtkanangtkana
提出日時 2020-01-13 20:49:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,501 bytes
コンパイル時間 2,656 ms
コンパイル使用メモリ 199,928 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-23 13:26:44
合計ジャッジ時間 3,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int inf = std::numeric_limits<int>::max();

  int q; std::cin >> q;
  loop(q) {
    int a, b, c;
    std::cin >> a >> b >> c;
    int ans = -2;
    if (a > c) std::swap(a, c);
    if (a==c) {
      if (a==b) {
        ans = 3 <= a ? 3 : -1;
      } else if (b==a-1) {
        ans = 2 <= b ? 2 : -1;
      } else {
        ans = 2 <= a ? 1 : -1;
      }
    } else {
      if (b < a || c < b) {
        ans = 0;
      } else {
        int now =  inf;
        if (2 <= a) cmn(now, b - a + 1);
        if (2 <= b - a) cmn(now, c - b + 1);
        if (now==inf) {
          ans = -1;
        } else {
          ans = now;
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

/*
a <= c としてよいです。
a = c の場合:
  3 つとも同じ場合は、値が 3 以上なら答えは 3、2以下なら不可能です。
  b = a - 1 の場合は、 b が 2 以上なら a, b をそれぞれ 1 ずつ下げるので 2、1 なら不可能です。
  その他の場合は、a だけ下げれば良いので、2<=a ? 1 : -1 です。
a < c の場合:
  b < a or a < c の場合は、もともと門松なので、0 です。
  それ以外の場合は、b か c の好きな方を下げます。
  2 <= a のとき、b を a - 1 まで下げられるので、b - a + 1 が候補です。
  2 <= b - a のとき、c を b - 1 まで下げられるので、c - b + 1 が候補です。
  どちらもできないときは、詰んでいます。
*/
0