結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2019-12-11 12:51:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,234 bytes |
| コンパイル時間 | 1,951 ms |
| コンパイル使用メモリ | 202,548 KB |
| 最終ジャッジ日時 | 2025-01-08 10:49:32 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 11 WA * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000
vector<pair<long long,long long>> V1,V2,V3,V4;
void dfs1(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money){
int n = a.size();
if(ind==n){
V1.emplace_back(money,love);
return;
}
else if(ind==n+1){
V2.emplace_back(money,love);
return;
}
dfs1(a,b,c,ind+1,love,money+a[ind]);
if(ind!=n-1)dfs1(a,b,c,ind+2,love+b[ind+1],money-c[ind+1]);
else dfs1(a,b,c,ind+2,love,money);
}
void dfs2(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool f){
int n = a.size();
if(ind==n){
if(f)V3.emplace_back(money,love);
else V4.emplace_back(money,love);
return;
}
else if(ind==n+1){
return;
}
dfs2(a,b,c,ind+1,love,money+a[ind],f);
if(ind!=n-1)dfs2(a,b,c,ind+2,love+b[ind+1],money-c[ind+1],f);
else dfs2(a,b,c,ind+2,love,money,f);
}
int main(){
int D;
cin>>D;
vector<long long> a(D),b(D),c(D);
for(int i=0;i<D;i++){
cin>>a[i]>>b[i]>>c[i];
}
vector<long long> a1,a2,b1,b2,c1,c2;
for(int i=0;i<D;i++){
if(i<D/2){
a1.push_back(a[i]);
b1.push_back(b[i]);
c1.push_back(c[i]);
}
else{
a2.push_back(a[i]);
b2.push_back(b[i]);
c2.push_back(c[i]);
}
}
dfs1(a1,b1,c1,0,0,0);
dfs2(a2,b2,c2,0,0,0,true);
if(b2.size()!=0)dfs2(a2,b2,c2,1,b2.front(),-c2.front(),false);
long long last = 0;
for(auto it = V3.rbegin();it!=V3.rend();it++){
(*it).second = max((*it).second,last);
last = (*it).second;
}
last=0;
for(auto it = V4.rbegin();it!=V4.rend();it++){
(*it).second = max((*it).second,last);
last = (*it).second;
}
long long ans = 0;
pair<long long,long long> P = make_pair(0,-Inf);
for(int i=0;i<V1.size();i++){
P.first = -V1[i].first;
auto it = lower_bound(V3.begin(),V3.end(),P);
if(it==V3.end())continue;
ans = max(ans,V1[i].second + (*it).second);
}
for(int i=0;i<V2.size();i++){
P.first = -V2[i].first;
auto it = lower_bound(V4.begin(),V4.end(),P);
if(it==V4.end())continue;
ans = max(ans,V2[i].second + (*it).second);
}
cout<<ans<<endl;
return 0;
}
沙耶花