結果
問題 | No.966 引き算をして門松列(その1) |
ユーザー |
![]() |
提出日時 | 2020-01-13 21:10:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 2,054 bytes |
コンパイル時間 | 1,932 ms |
コンパイル使用メモリ | 171,540 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-22 21:04:17 |
合計ジャッジ時間 | 2,513 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<ll, ll> P;#define DUMP(x) cout << #x << " = " << (x) << endl;#define FOR(i, m, n) for (ll i = m; i < n; i++)#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)#define REP(i, n) FOR(i, 0, n)#define IREP(i, n) IFOR(i, 0, n)#define FOREACH(x, a) for (auto&(x) : (a))#define ALL(v) (v).begin(), (v).end()#define SZ(x) ll(x.size())void solve() {vector<ll> a(3);REP(i, 3) { cin >> a[i]; }if (a[0] == a[1] && a[1] == a[2]) {// 1 1 1 -> -1// 2 2 2 -> -1if (a[0] <= 2) {cout << -1 << endl;return;}// 3 3 3 -> 3cout << 3 << endl;return;}// 両側2つ等しい// 2 1 2 -> -1// 1 2 1 -> -1if (a[0] == 1 && a[1] >= 2 && a[2] == 1 ||a[0] == 2 && a[1] == 1 && a[2] == 2) {cout << -1 << endl;return;}if (a[0] == a[2]) {if (a[0] == a[1] + 1) {// 4 3 4 -> 2cout << 2 << endl;return;}// 6 3 6 -> 1// 3 4 3 -> 1cout << 1 << endl;return;}ll mini = 1e18, maxi = -1;REP(i, 3) {mini = min(mini, a[i]);maxi = max(maxi, a[i]);}// 1 1 6 -> -1if (a[0] == a[1] && a[0] == 1 || a[1] == a[2] && a[2] == 1) {cout << -1 << endl;return;}// 2 2 1 -> -1// 1 2 2 -> -1if (a[1] == 2 && (a[0] == 2 && a[2] == 1 || a[0] == 1 && a[2] == 2)) {cout << -1 << endl;return;}// 3 3 2 -> 2if (a[0] == a[1] && a[1] - 1 == a[2] || a[1] == a[2] && a[1] - 1 == a[0]) {cout << 2 << endl;return;}if (a[0] == a[1] || a[1] == a[2]) {cout << 1 << endl;return;}// 全部異なる// 1 4 3// 4 2 3if (a[1] > a[0] && a[1] > a[2] || a[1] < a[0] && a[1] < a[2]) {cout << 0 << endl;return;}if (mini == 1) {if (a[1] == 2) {cout << -1 << endl;return;}cout << maxi - a[1] + 1 << endl;return;}cout << min(a[1] - mini + 1, maxi - a[1] + 1) << endl;}int main() {ll n;cin >> n;while (n--) solve();}