結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-25 10:12:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,245 bytes |
| コンパイル時間 | 1,262 ms |
| コンパイル使用メモリ | 162,348 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-01 20:00:23 |
| 合計ジャッジ時間 | 2,335 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
int main() {
int t;
cin >> t;
auto f = [](int cen,int l,int r){
int res = 0;
if( l > r) swap(l,r);
if(l == r && r == cen){
l -= 2;
cen --;
res += 3;
}
if(l == r){
l -= 2;
res += 2;
}
if(l == r-1){
l --;
res += 1;
}
if( r <= cen){
res += cen - r + 1;
cen = r -1;
}
if( cen <= l){
res += l - cen + 1;
l = cen - 1;
}
if( cen <= 0 || l <= 0 || r <= 0){
return -1;
}else{
return res;
}
};
rep(i,t){
int a,b,c;
cin >> a >> b >> c;
int res_a = f(a,b,c);
int res_b = f(c,a,b);
if(res_a == -1 && res_b == -1) cout << -1 << endl;
else if(res_a == -1) cout << res_b << endl;
else if(res_b == -1) cout << res_a << endl;
else cout << min(res_a,res_b) << endl;
}
return 0;
}