結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
mmn15277198
|
| 提出日時 | 2021-04-11 15:49:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,306 bytes |
| コンパイル時間 | 756 ms |
| コンパイル使用メモリ | 90,748 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 10:44:00 |
| 合計ジャッジ時間 | 1,308 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
const int INF = 1001001001;
int A , B , C;
int check (int a , int b , int c) {
return (a != b && b != c && c != a && (b > a && b > c || b < a && b < c) && a > 0 && b > 0 && c > 0);
}
int solve2 (int a , int b , int c) {
int ret = 0;
if (a == c) c -= 1;
if (a >= b) a -= (a - b + 1);
if (c >= b) c -= (c - b + 1);
if (check(a , b , c) == true) {
return abs(A - a) + abs(B - b) + abs(C - c);
} else {
return INF;
}
}
int solve3 (int a , int b , int c) {
if (b >= a) b -= (b - a + 1);
if (b >= c) b -= (b - c + 1);
if (a == c) a -= 1;
if (b >= a) b -= (b - a + 1);
if (b >= c) b -= (b - c + 1);
if (check(a , b , c) == true) {
return abs(A - a) + abs(B - b) + abs(C - c);
} else {
return INF;
}
}
void solve() {
cin >> A >> B >> C;
int cost1 = solve2 (A , B , C);
int cost2 = solve3 (A , B , C);
int cost = min(cost1 , cost2);
if (cost == INF) cost = -1;
cout << cost << endl;
return;
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
mmn15277198