結果
問題 |
No.966 引き算をして門松列(その1)
|
ユーザー |
|
提出日時 | 2020-09-03 20:12:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,404 bytes |
コンパイル時間 | 1,522 ms |
コンパイル使用メモリ | 166,228 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 00:17:32 |
合計ジャッジ時間 | 2,337 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | WA * 5 |
ソースコード
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair<ll, ll> pll; int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; rep(i, T) { ll A, B, C; cin >> A >> B >> C; ll ans = INF; if (B == 0) { cout << -1 << endl; } else if ((B > A && B > C) || (B < A && B < C)) { if (A != C) { cout << 0 << endl; } else if (A == 1) { cout << -1 << endl; } else { cout << 1 << endl; } } else { ll tmp = 0; bool j = 0; if (A == C) A--, j = 1, tmp = 1; // B最小化 ll mi = min(A, C) - 1; if (mi > 0) tmp += B - mi, ans = min(ans, tmp); // B最大化 tmp = 0; if (j) tmp = 1; ll a, c; if (A > C) a = B - 2, c = A - 1; else a = B - 1, c = A - 2; if (a > 0 && c > 0) tmp += (A - a) + (C - c), ans = min(ans, tmp); cout << (ans == INF ? -1 : ans) << endl; } } }