結果
問題 | No.968 引き算をして門松列(その3) |
ユーザー |
![]() |
提出日時 | 2020-01-13 20:50:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 1,176 bytes |
コンパイル時間 | 2,219 ms |
コンパイル使用メモリ | 194,724 KB |
最終ジャッジ日時 | 2025-01-08 17:37:08 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; while(a>=c) a--,b--,res+=x; while(c>=b) a--,c--,res+=z; 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; while(b>=a) b--,c--,res+=y; while(a>=c) a--,b--,res+=x; 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; }