結果

問題 No.2840 RGB Plates
ユーザー FplusFplusFFplusFplusF
提出日時 2024-08-09 22:18:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,622 ms / 2,000 ms
コード長 1,402 bytes
コンパイル時間 3,288 ms
コンパイル使用メモリ 256,396 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-08-18 00:56:18
合計ジャッジ時間 28,351 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
11,264 KB
testcase_01 AC 15 ms
11,392 KB
testcase_02 AC 21 ms
11,264 KB
testcase_03 AC 545 ms
11,264 KB
testcase_04 AC 14 ms
11,392 KB
testcase_05 AC 1,622 ms
7,168 KB
testcase_06 AC 23 ms
11,264 KB
testcase_07 AC 25 ms
11,392 KB
testcase_08 AC 24 ms
11,264 KB
testcase_09 AC 28 ms
11,264 KB
testcase_10 AC 1,135 ms
7,296 KB
testcase_11 AC 23 ms
11,264 KB
testcase_12 AC 1,318 ms
7,168 KB
testcase_13 AC 812 ms
7,296 KB
testcase_14 AC 1,191 ms
7,168 KB
testcase_15 AC 1,063 ms
7,168 KB
testcase_16 AC 947 ms
7,168 KB
testcase_17 AC 1,184 ms
7,296 KB
testcase_18 AC 1,607 ms
7,168 KB
testcase_19 AC 1,614 ms
7,168 KB
testcase_20 AC 1,575 ms
7,168 KB
testcase_21 AC 1,582 ms
7,296 KB
testcase_22 AC 1,558 ms
7,168 KB
testcase_23 AC 451 ms
11,392 KB
testcase_24 AC 381 ms
11,264 KB
testcase_25 AC 529 ms
11,264 KB
testcase_26 AC 961 ms
7,168 KB
testcase_27 AC 704 ms
7,168 KB
testcase_28 AC 721 ms
7,168 KB
testcase_29 AC 924 ms
7,296 KB
testcase_30 AC 1,502 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    else mx=1e4;
    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';
}
0