結果

問題 No.2840 RGB Plates
ユーザー pockynypockyny
提出日時 2024-08-09 22:25:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,924 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 74,892 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-08-18 00:56:55
合計ジャッジ時間 29,113 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,632 KB
testcase_01 AC 5 ms
5,504 KB
testcase_02 AC 7 ms
5,504 KB
testcase_03 AC 314 ms
5,504 KB
testcase_04 AC 5 ms
5,504 KB
testcase_05 AC 1,892 ms
5,504 KB
testcase_06 AC 7 ms
5,632 KB
testcase_07 AC 8 ms
5,504 KB
testcase_08 AC 7 ms
5,504 KB
testcase_09 AC 10 ms
5,504 KB
testcase_10 AC 825 ms
5,504 KB
testcase_11 AC 7 ms
5,504 KB
testcase_12 AC 1,556 ms
5,504 KB
testcase_13 AC 990 ms
5,504 KB
testcase_14 AC 1,431 ms
5,632 KB
testcase_15 AC 1,289 ms
5,632 KB
testcase_16 AC 1,174 ms
5,504 KB
testcase_17 AC 1,408 ms
5,504 KB
testcase_18 AC 1,924 ms
5,632 KB
testcase_19 AC 1,919 ms
5,632 KB
testcase_20 AC 1,917 ms
5,632 KB
testcase_21 AC 1,919 ms
5,760 KB
testcase_22 AC 1,922 ms
5,504 KB
testcase_23 AC 248 ms
5,504 KB
testcase_24 AC 208 ms
5,760 KB
testcase_25 AC 297 ms
5,504 KB
testcase_26 AC 1,185 ms
5,504 KB
testcase_27 AC 858 ms
5,760 KB
testcase_28 AC 880 ms
5,632 KB
testcase_29 AC 1,129 ms
5,632 KB
testcase_30 AC 1,822 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>

using namespace std;
typedef long long ll;
const int B = 70000;
int dp[2*B + 10][2],ndp[2*B + 10][2],a[3010],inf = 1000000000;
int main(){
    int i,j,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=0;i<=2*B;i++) dp[i][0] = dp[i][1] = ndp[i][0] = ndp[i][1] = -inf;
    dp[B][0] = 0;
    for(i=0;i<n;i++){
        for(j=0;j<=2*B;j++){
            for(int k=0;k<2;k++){
                if(dp[j][k]<0) continue;
                ndp[j][k] = max(ndp[j][k],dp[j][k] + a[i]);
            }
            for(int k=0;k<2;k++){
                if(dp[j][k]<0) continue;
                if(j>=a[i]) ndp[j - a[i]][1] = max(ndp[j - a[i]][k],dp[j][k]);
                if(j + a[i]<=2*B) ndp[j + a[i]][1] = max(ndp[j + a[i]][k],dp[j][k]);
            }
        }
        for(j=0;j<=2*B;j++){
            for(int k=0;k<2;k++){
                dp[j][k] = ndp[j][k]; ndp[j][k] = -inf;
            }
        }
    }
    // cout << dp[B][0] << " " << dp[B][1] << endl;
    if(dp[B][1]<=0){
        cout << -1 << "\n";
    }else{
        cout << dp[B][1] << "\n";
    }
}
0