結果

問題 No.967 引き算をして門松列(その2)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-02-20 20:16:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 71,264 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 06:29:25
合計ジャッジ時間 1,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,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 <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  int N; cin >> N;

  rep(i, N) {
    int a,b,c,x,y,z;
    cin >> a >> b >> c >> x >> y >> z;
    // Bを一番大きくする(=A,Cを小さくする)
    int A = a, B = b, C = c;
    int cost1 = 0, cost2 = 0;
    if (B <= A) {cost1 += (A - B + 1) * x; A = B-1;}
    if (B <= C) {cost1 += (C - B + 1) * z; C = B-1;}
    if (A == C) {
      cost1 += min(x, z);
      --A;
    }
    if (A <= 0 || C <= 0)
      cost1 = -1;

    // BをA,Cより小さくする
    A = a, B = b, C = c;
    if (A == C) {cost2 += min(x, z); --A;}
    if (B > min(A, C)) {cost2 += (B - min(A, C) + 1) * y; B = min(A, C) - 1;}
    if (A <= 0 || B <= 0 || C <= 0)
      cost2 = -1;

    if (cost1 == -1 && cost2 == -1) cout << -1 << endl;
    else if (cost1 == -1) cout << cost2 << endl;
    else if (cost2 == -1) cout << cost1 << endl;
    else cout << min(cost1, cost2) << endl;
  }
  return 0;
}
0