結果
問題 | No.974 最後の日までに |
ユーザー | Chanyuh |
提出日時 | 2020-05-05 00:13:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 847 ms / 2,000 ms |
コード長 | 2,264 bytes |
コンパイル時間 | 2,255 ms |
コンパイル使用メモリ | 108,916 KB |
実行使用メモリ | 40,384 KB |
最終ジャッジ日時 | 2023-09-07 11:58:25 |
合計ジャッジ時間 | 22,043 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 654 ms
40,080 KB |
testcase_01 | AC | 706 ms
40,252 KB |
testcase_02 | AC | 697 ms
40,080 KB |
testcase_03 | AC | 684 ms
40,096 KB |
testcase_04 | AC | 697 ms
40,056 KB |
testcase_05 | AC | 722 ms
40,384 KB |
testcase_06 | AC | 719 ms
40,084 KB |
testcase_07 | AC | 714 ms
40,104 KB |
testcase_08 | AC | 716 ms
40,204 KB |
testcase_09 | AC | 746 ms
40,160 KB |
testcase_10 | AC | 765 ms
40,316 KB |
testcase_11 | AC | 781 ms
40,232 KB |
testcase_12 | AC | 743 ms
40,228 KB |
testcase_13 | AC | 744 ms
40,224 KB |
testcase_14 | AC | 741 ms
40,100 KB |
testcase_15 | AC | 783 ms
40,060 KB |
testcase_16 | AC | 764 ms
40,240 KB |
testcase_17 | AC | 32 ms
4,384 KB |
testcase_18 | AC | 30 ms
4,380 KB |
testcase_19 | AC | 29 ms
4,384 KB |
testcase_20 | AC | 33 ms
4,384 KB |
testcase_21 | AC | 35 ms
4,384 KB |
testcase_22 | AC | 33 ms
4,384 KB |
testcase_23 | AC | 33 ms
4,380 KB |
testcase_24 | AC | 33 ms
4,384 KB |
testcase_25 | AC | 2 ms
4,380 KB |
testcase_26 | AC | 2 ms
4,380 KB |
testcase_27 | AC | 574 ms
35,368 KB |
testcase_28 | AC | 789 ms
40,140 KB |
testcase_29 | AC | 2 ms
4,384 KB |
testcase_30 | AC | 77 ms
4,384 KB |
testcase_31 | AC | 2 ms
4,380 KB |
testcase_32 | AC | 2 ms
4,384 KB |
testcase_33 | AC | 462 ms
26,068 KB |
testcase_34 | AC | 847 ms
40,096 KB |
testcase_35 | AC | 1 ms
4,380 KB |
testcase_36 | AC | 1 ms
4,384 KB |
testcase_37 | AC | 122 ms
4,380 KB |
testcase_38 | AC | 1 ms
4,380 KB |
testcase_39 | AC | 1 ms
4,380 KB |
testcase_40 | AC | 21 ms
4,380 KB |
testcase_41 | AC | 28 ms
4,380 KB |
testcase_42 | AC | 138 ms
4,384 KB |
testcase_43 | AC | 143 ms
4,384 KB |
testcase_44 | AC | 104 ms
4,384 KB |
testcase_45 | AC | 88 ms
4,380 KB |
testcase_46 | AC | 2 ms
4,380 KB |
testcase_47 | AC | 1 ms
4,384 KB |
testcase_48 | AC | 2 ms
4,380 KB |
testcase_49 | AC | 1 ms
4,380 KB |
testcase_50 | AC | 2 ms
4,380 KB |
testcase_51 | AC | 1 ms
4,380 KB |
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int n; ll a[55],b[55],c[55]; void rec(int s,int finish,map<ll,ll> &ma,ll money,ll love){ //cout << s << endl; if(s==finish){ ma[money]=max(ma[money],love); return; } rec(s+1,finish,ma,money+a[s],love); if(s+2<=finish) rec(s+2,finish,ma,money-c[s+1],love+b[s+1]); } ll solve(int mid){ map<ll,ll> former,latter; former.clear(); latter.clear(); rec(0,mid,former,0,0); rec(mid,n,latter,0,0); latter[-INF]=-INF; auto id=latter.end();id--; map<ll,ll> max_latter; max_latter.clear(); ll L=-INF; while(true){ ll money=(*id).first,love=(*id).second; //cout << money << " " << love << endl; L=max(L,love); max_latter[money]=L; if(id==latter.begin()) break; id--; } id=max_latter.end();id--; ll M=(*id).first; ll ans=0; for(auto p:former){ ll money=p.first,love=p.second; while(M+money>=0){ id--; M=(*id).first;L=(*id).second; if(M+money<0){ id++; M=(*id).first;L=(*id).second; break; } } if(M+money>=0)ans=max(ans,L+love); } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); cin >> n; rep(i,n){ cin >> a[i] >> b[i] >> c[i]; } cout << max(solve(n/2),solve(n/2+1)) << endl; }