結果

問題 No.967 引き算をして門松列(その2)
ユーザー recososorecososo
提出日時 2020-01-13 21:15:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 806 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 166,172 KB
実行使用メモリ 814,632 KB
最終ジャッジ日時 2023-08-24 13:56:01
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y,z;
ll f(int a,int b,int c){
    if(a<1||b<1||c<1){
        return 1e18;
    }
    if(a==b||b==c||c==a){
        return min({f(a-1,b,c)+x,f(a,b-1,c)+y,f(a,b,c-1)+z});
    }
    if(min({a,b,c})==b||max({a,b,c})==b){
        return 0;
    }
    else{
        if(a<c){
            return min({f(a,a,c)+(b-a)*y,f(a,b,b)+(c-b)*z,f(a,b,a)+(c-a)*z});
        }
        else{
            return min({f(b,b,c)+(a-b)*x,f(c,b,c)*(a-c)*x,f(a,c,c)+(b-c)*y});
        }
    }
}
int main(){
    int t;cin >> t;
    ll a,b,c;
    for(int i=0;i<t;i++){
        cin >> a >> b >> c >> x >> y >> z;
        ll ans=f(a,b,c);
        if(ans>=1e18){
            cout << -1 << endl;
        }
        else{
            cout << ans << endl;
        }
    }
}
0