結果

問題 No.966 引き算をして門松列(その1)
ユーザー tooftoof
提出日時 2020-01-13 22:13:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 200,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:02:31
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n), b(n), c(n);
  rep(i, n) {
    cin >> a[i] >> b[i] >> c[i];
  }

  constexpr ll inf = 1LL << 60;
  rep(i, n) {
    ll s = 0;
    ll t = 0;

    [&s](ll a, ll b, ll c) {
      if (b < 3) {
        s = inf;
        return;
      }
      if (a >= b) {
        s += a-(b-1);
        a = b-1;
      }
      if (c >= b) {
        s += c-(b-1);
        c = b-1;
      }
      if (a == c) {
        s++;
      }
    }(a[i], b[i], c[i]);

    [&t](ll a, ll b, ll c) {
      if (min(a, c) < 2 or (c <= 2 and a <= 2)) {
        t = inf;
        return;
      }
      if (b >= min(a, c)) {
        t += b-(min(a, c)-1);
        b = min(a, c)-1;
      }
      if (a == c) {
        t++;
        if (b+1 == a) t++;
      }
    }(a[i], b[i], c[i]);
    //cerr << s << " " << t << endl;

    if (s == inf and t == inf) {
      cout << -1 << endl;
    } else {
      cout << min(s, t) << endl;
    }
  }
}
0