結果

問題 No.967 引き算をして門松列(その2)
ユーザー kappybarkappybar
提出日時 2020-03-31 15:23:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 165,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 23:18:58
合計ジャッジ時間 3,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
    int t;
    cin >> t;
    auto f = [](int cen,int l,int r,ll x,ll y,ll z){
        ll res = 0;
        if( l > r) {swap(l,r);swap(y,z);}
        if(l == r && r == cen){
            l -= 2;
            cen --;
            res += 2*y + x;
        }
        if(l == r){
             l -= 2;
             res += 2*y;
         }
         if(l == r-1){
              l --;
              res += y;
         }
         if( r <= cen){
            res += (cen - r + 1)*x;
             cen = r -1;
         }
         if( cen <= l){
             res += (l - cen + 1)*y;
             l = cen - 1;
         }
         if( cen <= 0 || l <= 0 || r <= 0){
             return (ll)(-1);
         }else{
             return res;
         }
    };

    rep(i,t){
        int a,b,c;
        ll x,y,z;
        cin >> a >> b >> c >>x >> y >> z;
        ll res_a = f(a,b,c,x,y,z);
        ll res_b = f(c,a,b,z,x,y);
        if(res_a == -1 && res_b == -1) cout << -1 << endl;
        else if(res_a == -1) cout << res_b << endl;
        else if(res_b == -1) cout << res_a << endl;
        else cout << min(res_a,res_b) << endl;
    }

    
    return 0;

    
}
0