結果

問題 No.967 引き算をして門松列(その2)
ユーザー recososorecososo
提出日時 2020-01-13 21:44:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 175,556 KB
実行使用メモリ 6,468 KB
最終ジャッジ日時 2023-08-24 15:57:18
合計ジャッジ時間 2,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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){
        if(a==b){
            res=min(f(a-1,b,c)+x,f(a,b-1,c)+y);
        }
        else if(b==c){
            res=min(f(a,b-1,c)+y,f(a,b,c-1)+z);
        }
        else{
            res=min(f(a,b,c-1)+z,f(a-1,b,c)+x);
        }
    }
    else if(min({a,b,c})==b||max({a,b,c})==b){
        res=0;
    }
    else{
        if(a<c){
            res=min({f(a,a-1,c)+(b-a+1)*y,f(a,b,b-1)+(c-b+1)*z,f(a,b,a-1)+(c-a+1)*z});
        }
        else{
            res=min({f(b-1,b,c)+(a-b+1)*x,f(a,c-1,c)+(b-c+1)*y,f(c-1,b,c)+(a-c+1)*z});
        }
    }
    return mp[{a,{b,c}}]=res;
}
int main(){
    int t;cin >> t;
    for(int i=0;i<t;i++){
        ll a,b,c;cin >> a >> b >> c >> x >> y >> z;
        ll ans=f(a,b,c);
        if(ans>=1e18){
            cout << -1 << endl;
        }
        else{
            cout << ans << endl;
        }
    }
}
0