結果

問題 No.966 引き算をして門松列(その1)
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2020-03-21 20:00:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 822 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 163,396 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-25 00:47:26
合計ジャッジ時間 2,186 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void solve() {
	const int64_t INF = 1e18;
	int64_t a, b, c; cin >> a >> b >> c;
	int64_t ans = INF;
	// b = max
	if(b >= 3 and not(a == 1 and c == 1)) {
		if(a == c) {
			ans = min<int64_t>(ans, max<int64_t>(0, a - (b - 1)) + 1);
		} else {
			ans = min<int64_t>(ans, max<int64_t>(0, a - (b - 1)) + max<int64_t>(0, c - (b - 2)));
			ans = min<int64_t>(ans, max<int64_t>(0, a - (b - 2)) + max<int64_t>(0, c - (b - 1)));
		}
	}
	// b = min
	if(not (a == 1 or c == 1) and (a > 2 or c > 2)) {
		if(a == c) {
			ans = min<int64_t>(ans, max<int64_t>(0, b - (a - 2)) + 1);
		} else {
			ans = min<int64_t>(ans, max<int64_t>(0, b - (min<int64_t>(a, c) - 1)));
		}
	}
	cout << (ans == INF ? -1 : ans) << '\n';
}

int main() {
	int t; cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}
0