結果
| 問題 |
No.2840 RGB Plates
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-08-09 22:17:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,385 bytes |
| コンパイル時間 | 3,151 ms |
| コンパイル使用メモリ | 257,512 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-08-09 22:17:48 |
| 合計ジャッジ時間 | 14,685 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((ll)v.size())
template<class T> inline bool chmin(T &a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n);
ll mx=0;
rep(i,n){
cin >> a[i];
chmax(mx,a[i]);
}
mt19937 mt;
shuffle(all(a),mt);
if(n<=500) mx=2e4;
vector<vector<ll>> dp(mx*2+1,vector<ll>(8,-INF)),ndp=dp;
dp[mx][0]=0;
rep(i,n){
rep(j,mx*2+1){
rep(k,8){
if(dp[j][k]==-INF) continue;
chmax(ndp[j][k|1],dp[j][k]+a[i]);
if(j+a[i]<=mx*2) chmax(ndp[j+a[i]][k|2],dp[j][k]);
if(0<=j-a[i]) chmax(ndp[j-a[i]][k|4],dp[j][k]);
}
}
swap(dp,ndp);
ndp.assign(mx*2+1,vector<ll>(8,-INF));
}
if(dp[mx][7]==-INF) cout << "-1\n";
else cout << dp[mx][7] << '\n';
}
FplusFplusF