結果

問題 No.968 引き算をして門松列(その3)
ユーザー FF256grhyFF256grhy
提出日時 2020-01-13 21:42:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,717 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 165,812 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 15:52:46
合計ジャッジ時間 2,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int t;
	cin >> t;
	
	auto f = [](LL a, LL b, LL c, LL x, LL y, LL z) -> LL {
		LL val = 0, cnt = 0, lim = min({ a, b, c }) - 1;
		if(a == c) {
			if_not(x <= z) { swap(x, z); }
			a++;
			cnt++;
			val += x;
		}
		if(cnt > lim) { return -1; }
		
		if(a < b && b > c) { return val; }
		if(a > b && b < c) { return val; }
		
		if_not(a > c) { swap(a, c); swap(x, z); }
		
		LL cnt_s = a + 1 - b;
		LL val_s = cnt_s * y;
		
		LL cnt_t = 0;
		LL val_t = 0;
		if(a < b + 1) { cnt_t += b + 1 - a; val_t += x * (b + 1 - a); a = b + 1; }
		if(c < b + 1) { cnt_t += b + 1 - c; val_t += z * (b + 1 - c); c = b + 1; }
		if(a == c) { cnt_t++; val_t += min(x, z); }
		
		LL INF = 4'000'000'000'000'000'000, ans = INF;
		if(cnt + cnt_s <= lim) { setmin(ans, val + val_s); }
		if(cnt + cnt_t <= lim) { setmin(ans, val + val_t); }
		if(ans == INF) { return -1; }
		
		return ans;
	};
	
	inc(q, t) {
		LL a, b, c, x, y, z;
		cin >> a >> b >> c >> z >> x >> y;
		
		cout << f(a, b, c, x, y, z) << "\n";
	}
	
	return 0;
}
0