結果

問題 No.966 引き算をして門松列(その1)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-11-08 23:23:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 84,712 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-13 06:34:04
合計ジャッジ時間 2,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int f(int a, int b, int c){
    int e = 0;
    if(a==c){
      a--;
      e++;
    }
    int mn = 2000000010;
    if(b>=3&&max(a,c)>=2){
      int d = 0;
      d += max(0,max(a,c)-(b-1));
      d += max(0,min(a,c)-(b-2));
      mn = min(mn,d+e);
    }
    if(max(a,c)>=3&&min(a,c)>=2){
      int d = 0;
      d += max(0,b-(min(a,c)-1));
      mn = min(mn,d+e);
    }
    if(mn==2000000010){
      return -1;
    }
    else{
      return mn;
    }
}

int main(){
  int T;
  cin>>T;
  for(int t = 0; t < T; t++){
    int a,b,c;
    cin>>a>>b>>c;
    cout << f(a,b,c) << endl;
  }
  return 0;
}
0