結果
問題 | No.967 引き算をして門松列(その2) |
ユーザー |
![]() |
提出日時 | 2019-11-09 12:56:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,776 bytes |
コンパイル時間 | 969 ms |
コンパイル使用メモリ | 97,508 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-15 15:47:24 |
合計ジャッジ時間 | 2,110 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 1000000007ll isK(ll a, ll b, ll c){vector<pair<ll,ll> > v;v.pb(mp(a,0));v.pb(mp(b,1));v.pb(mp(c,2));sort(all(v));if(v[0].fi!=v[1].fi&&v[1].fi!=v[2].fi){if(v[0].se==1||v[2].se==1){return 1;}}return 0;}ll f(ll a, ll b, ll c, ll x, ll y, ll z){ll mn = 2000000000000000010LL;ll d[3];ll d1[3] = {a,b,c};ll d2[3] = {x,y,z};vector<ll> v;rep(i,0,3)v.pb(i);do{if(isK(v[0],v[1],v[2])==0)continue;rep(i,0,3){d[i] = v[i];}ll e1[3] = {d1[d[0]],d1[d[1]],d1[d[2]]};ll e2[3] = {d2[d[0]],d2[d[1]],d2[d[2]]};ll cost = 0;rep(i,0,2){ll q = max(0LL,(e1[i+1]-(e1[i]-1)));cost += q*e2[i+1];e1[i+1]-=q;}if(e1[2]>0){mn = min(mn,cost);}}while(next_permutation(all(v)));if(mn==2000000000000000010LL){return -1;}return mn;}int main(){ll T;cin>>T;rep(t,0,T){ll a,b,c,x,y,z;cin>>a>>b>>c>>x>>y>>z;cout << f(a,b,c,x,y,z) << endl;}return 0;}