結果

問題 No.966 引き算をして門松列(その1)
ユーザー Shun TakaseShun Takase
提出日時 2020-01-14 00:41:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,161 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 169,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 21:46:50
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int T;
    cin >> T;
    vector<ll> ans;
    auto is_kado = [](ll a, ll b, ll c){
        if(a == b || b == c || a == c) return false;
        vector<ll> v = {a,b,c};
        SORT(v);
        return (v[1]== a || v[1] == c);
    };
    REP(it, T){
        int a,b,c;
        cin >> a >> b >> 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){
            ans.pb(-1);
        }
        else{
            ans.pb(mn);
        }
    }

    for(auto&& aa : ans) pr(aa);
}
0