結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-01-13 20:46:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,983 bytes |
| コンパイル時間 | 1,764 ms |
| コンパイル使用メモリ | 175,536 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-21 16:45:16 |
| 合計ジャッジ時間 | 2,295 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
///////////////////////////////////////////////////////////////
int f1(int A, int B, int C) {
int res = 0;
if (A>= B) {
res += A-B+1;
A = B-1;
}
if (C >= A) {
res += C-A+1;
C = A-1;
}
if (A <= 0 || C <= 0) return INF;
return res;
}
int f2(int A, int B, int C) {
int res = 0;
if (C >= B) {
res += C-B+1;
C = B-1;
}
if (A >= C) {
res += A-C+1;
A = C-1;
}
if (A <= 0 || C <= 0) return INF;
return res;
}
int f3(int A, int B, int C) {
int res = 0;
if (A >= C) {
res += A-C+1;
A = C-1;
}
if (B >= A) {
res += B-A+1;
B = A-1;
}
if (B <= 0 || A <= 0) return INF;
return res;
}
int f4(int A, int B, int C) {
int res = 0;
if (C >= A) {
res += C-A+1;
C = A-1;
}
if (B >= C) {
res += B-C+1;
B = C-1;
}
if (B <= 0 || C <= 0) return INF;
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int T; cin >> T;
while (T--) {
int A,B,C; cin >> A >> B >> C;
int ans = INF;
chmin(ans,f1(A,B,C));
chmin(ans,f2(A,B,C));
chmin(ans,f3(A,B,C));
chmin(ans,f4(A,B,C));
if (ans == INF) cout << -1 << endl;
else cout << ans << endl;
}
}
minato