結果

問題 No.967 引き算をして門松列(その2)
ユーザー tempura_pptempura_pp
提出日時 2020-01-13 20:34:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 94,772 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:04:53
合計ジャッジ時間 1,874 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void solve(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll s,t,u;
    cin>>s>>t>>u;
    ll target[]={a-1,a,b-2,b-1,b,b+1,b+2,c-1,c};
    ll ans = longinf;
    rep(i,9)rep(j,9)rep(k,9){
        ll x = target[i],y=target[j],z=target[k];
        if(x>a||y>b||z>c)continue;
        if(x<=0 ||y<= 0||z<=0)continue;
        if(x==y||y==z||z==x)continue;
        if(y>x && y>z) ans = min(ans,s*(a-x)+t*(b-y)+u*(c-z));
        if(y<x && y<z) ans = min(ans,s*(a-x)+t*(b-y)+u*(c-z));
    }
    if(ans == longinf)cout<<-1<<endl;
    else cout<<ans<<endl;
}
int main(){
    int t;
    cin>>t;
    rep(i,t)solve();
    return 0;
}
0