結果

問題 No.966 引き算をして門松列(その1)
ユーザー beetbeet
提出日時 2020-01-13 20:27:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 776 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 197,712 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 12:58:44
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int INF = 1e18;
Int p1(Int a,Int b,Int c){
  // a < b > c
  if(b==2) return INF;
  Int res=0;
  if(a>=b) res+=a-b+1,a=b-1;
  if(c>=b) res+=c-b+1,c=b-1;
  if(a==c) res++;
  return res;
}

Int p2(Int a,Int b,Int c){
  Int res=0;
  if(a==c) a--,res++;
  if(min(a,c)<=1) return INF;
  res+=b-min(a,c)+1;
  return res;
}

signed solve(){
  Int a,b,c;
  cin>>a>>b>>c;
  Int ans=min(p1(a,b,c),p2(a,b,c));
  if(ans==INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}

signed main(){
  Int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
0