結果
問題 |
No.968 引き算をして門松列(その3)
|
ユーザー |
![]() |
提出日時 | 2020-01-13 20:52:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,324 bytes |
コンパイル時間 | 2,119 ms |
コンパイル使用メモリ | 193,776 KB |
最終ジャッジ日時 | 2025-01-08 17:38:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE const Int INF = 1e18; Int p1_1(Int a,Int b,Int c,Int x,Int y,Int z){ // a < b > c, a < c < b Int res=0; if(a>=c){ Int d=a-c+1; a-=d; b-=d; res+=x*d; } if(c>=b){ Int d=c-b+1; a-=d; c-=d; res+=z*d; } assert(a < c && c < b); if(min({a,b,c})<=0) return INF; return res; } Int p1(Int a,Int b,Int c,Int x,Int y,Int z){ // a < b > c return min(p1_1(a,b,c,x,y,z),p1_1(c,b,a,y,x,z)); } Int p2_1(Int a,Int b,Int c,Int x,Int y,Int z){ // a > b < c, b < a < c Int res=0; if(b>=a){ Int d=b-a+1; b-=d; c-=d; res+=y*d; } if(a>=c){ Int d=a-c+1; a-=d; b-=d; res+=x*d; } assert(b < a && a < c); if(min({a,b,c})<=0) return INF; return res; } Int p2(Int a,Int b,Int c,Int x,Int y,Int z){ // a > b < c return min(p2_1(a,b,c,x,y,z),p2_1(c,b,a,y,x,z)); } signed solve(){ Int a,b,c,x,y,z; cin>>a>>b>>c>>x>>y>>z; Int ans=min(p1(a,b,c,x,y,z),p2(a,b,c,x,y,z)); if(ans==INF) ans=-1; cout<<ans<<endl; return 0; } signed main(){ Int T; cin>>T; while(T--) solve(); return 0; }