結果

問題 No.967 引き算をして門松列(その2)
ユーザー recososorecososo
提出日時 2020-01-13 21:29:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 933 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 174,272 KB
実行使用メモリ 538,572 KB
最終ジャッジ日時 2023-08-24 15:07:01
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,768 KB
testcase_01 AC 1 ms
4,384 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;
map<pair<ll,pair<ll,ll>>,ll> mp;
ll f(ll a,ll b,ll c){
    if(mp[{a,{b,c}}]){
        return mp[{a,{b,c}}];
    }
    ll res;
    if(a<1||b<1||c<1){
        res=1e18;
    }
    else if(a==b||b==c||c==a){
        res=min({f(a-1,b,c)+x,f(a,b-1,c)+y,f(a,b,c-1)+z});
    }
    else if(min({a,b,c})==b||max({a,b,c})==b){
        res=0;
    }
    else{
        if(a<c){
            res=min({f(a,a,c)+(b-a)*y,f(a,b,b)+(c-b)*z,f(a,b,a)+(c-a)*z});
        }
        else{
            res=min({f(b,b,c)+(a-b)*x,f(c,b,c)*(a-c)*x,f(a,c,c)+(b-c)*y});
        }
    }
    return mp[{a,{b,c}}]=res;
}
int main(){
    int t;cin >> t;
    ll a,b,c,ans;
    for(int i=0;i<t;i++){
        cin >> a >> b >> c >> x >> y >> z;
        ans=f(a,b,c);
        if(ans>=1e18){
            cout << -1 << endl;
        }
        else{
            cout << ans << endl;
        }
    }
}
0