結果
問題 | No.967 引き算をして門松列(その2) |
ユーザー |
![]() |
提出日時 | 2019-12-29 23:00:53 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,734 bytes |
コンパイル時間 | 840 ms |
コンパイル使用メモリ | 87,316 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:55:01 |
合計ジャッジ時間 | 1,978 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=b-1LL;i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define endl "\n" #define print(x) cout<<#x<<" = "<<x<<endl; #define MOD 1000000007 ll f(ll a, ll b, ll c, ll x, ll y, ll z){ ll ret = 0; ll d1 = max(0LL,b-(a-1)); ret += y*d1; b -= d1; ll d2 = max(0LL,c-(b-1)); ret += z*d2; c -= d2; if(c>0){ return ret; } else{ return 2000000000000000010LL; } } int main(){ int T; cin>>T; for(int t = 0; t < T; t++){ ll d[3]; ll e[3]; cin>>d[0]>>d[1]>>d[2]>>e[0]>>e[1]>>e[2]; rep(i,0,3){ if(d[i]<1||1000000000<d[i]){ cout << -2 << endl; continue; } if(e[i]<1||1000000000<e[i]){ cout << -2 << endl; continue; } } ll ans = 2000000000000000010LL; ans = min(ans,f(d[1],d[0],d[2],e[1],e[0],e[2])); ans = min(ans,f(d[1],d[2],d[0],e[1],e[2],e[0])); ans = min(ans,f(d[0],d[2],d[1],e[0],e[2],e[1])); ans = min(ans,f(d[2],d[0],d[1],e[2],e[0],e[1])); if(ans==2000000000000000010LL){ cout << -1 << endl; } else{ cout << ans << endl; } } return 0; }