結果

問題 No.2840 RGB Plates
ユーザー みここ
提出日時 2024-08-09 22:52:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 69,852 KB
最終ジャッジ日時 2025-02-23 21:59:15
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
using namespace std;

bitset<2000001> b;
bitset<2000001> e;
bitset<2000001> c;

int main()
{
    int n;
    cin >> n;
    b.set(0, true);
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        s += a;
        c = b << a;
        e |= b & c;
        b |= c;
    }
    for (int i = 1; i * 2 < s; i++)
    {
        if (e[i])
        {
            cout << s - i * 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}
0