結果

問題 No.968 引き算をして門松列(その3)
ユーザー LayCurseLayCurse
提出日時 2020-01-13 21:11:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,686 bytes
コンパイル時間 2,683 ms
コンパイル使用メモリ 209,728 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-24 13:48:41
合計ジャッジ時間 3,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 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 #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
long long solve(long long a, long long b, long long c, long long x, long long y, long long z){
  long long v;
  long long res = 0;
  if(a >= b){
    v = a-b+1;
    res += y * v;
    a -= v;
    c -= v;
  }
  if(b >= c){
    v = b-c+1;
    res += z * v;
    a -= v;
    b -= v;
  }
  if(a <= 0){
    res = 4611686016279904256LL;
  }
  return res;
}
int main(){
  int Lj4PdHRW;
  int A;
  int B;
  int C;
  int X;
  int Y;
  int Z;
  long long res;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    res = 4611686016279904256LL;
    rd(A);
    rd(B);
    rd(C);
    rd(Y);
    rd(Z);
    rd(X);
    chmin(res, solve(A,C,B,X,Z,Y));
    chmin(res, solve(B,A,C,Y,X,Z));
    chmin(res, solve(C,A,B,Z,X,Y));
    chmin(res, solve(B,C,A,Y,Z,X));
    if(res==4611686016279904256LL){
      wt_L(-1);
      wt_L('\n');
    }
    else{
      wt_L(res);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200112-1

// --- original code ---
// ll solve(ll a, ll b, ll c, ll x, ll y, ll z){
//   ll v, res = 0;
//   if(a >= b){
//     v = a-b+1;
//     res += y * v;
//     a -= v; c -= v;
//   }
//   if(b >= c){
//     v = b-c+1;
//     res += z * v;
//     a -= v; b -= v;
//   }
//   if(a <= 0) res = ll_inf;
//   return res;
// }
// 
// {
//   int A, B, C, X, Y, Z;
//   ll res;
//   REP(rd_int()){
//     res = ll_inf;
//     rd(A,B,C,Y,Z,X);
//     res <?= solve(A,C,B,X,Z,Y);
//     res <?= solve(B,A,C,Y,X,Z);
//     res <?= solve(C,A,B,Z,X,Y);
//     res <?= solve(B,C,A,Y,Z,X);
//     wt(if[res==ll_inf,-1,res]);
//   }
// }
0