結果

問題 No.2840 RGB Plates
ユーザー NachiaNachia
提出日時 2024-08-09 22:04:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,732 ms / 2,000 ms
コード長 1,623 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 108,912 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-08-18 00:56:05
合計ジャッジ時間 19,283 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 28 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1,715 ms
7,424 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1,732 ms
7,552 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1,405 ms
7,424 KB
testcase_13 AC 396 ms
5,376 KB
testcase_14 AC 1,269 ms
7,548 KB
testcase_15 AC 514 ms
5,376 KB
testcase_16 AC 465 ms
5,376 KB
testcase_17 AC 1,244 ms
7,424 KB
testcase_18 AC 1,716 ms
7,424 KB
testcase_19 AC 1,713 ms
7,424 KB
testcase_20 AC 776 ms
5,376 KB
testcase_21 AC 774 ms
5,376 KB
testcase_22 AC 775 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 19 ms
5,376 KB
testcase_25 AC 26 ms
5,376 KB
testcase_26 AC 479 ms
5,376 KB
testcase_27 AC 134 ms
5,376 KB
testcase_28 AC 138 ms
5,376 KB
testcase_29 AC 460 ms
5,504 KB
testcase_30 AC 738 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
#include <atcoder/modint>
#include <bitset>
#include <type_traits>
namespace nachia{
template<class TargetInt, TargetInt Max, TargetInt Min = TargetInt(1), class Callback>
void CallWithConstexprFittingInt(TargetInt val, const Callback& callback){
    if(Max / 2 < val || Max / 2 < Min){ callback(std::integral_constant<TargetInt, Max>()); return; }
    CallWithConstexprFittingInt<TargetInt, Max / 2, Min, Callback>(val, callback);
}
}
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    int N; cin >> N;
    vector<int> A(N); rep(i,N) cin >> A[i];
    int Z = 0;
    for(auto a : A) Z += a;
    int ans = -1;
    nachia::CallWithConstexprFittingInt<int, 1<<23>(Z/2+1, [&](auto X){
        constexpr int x = X.value;
        using Set = bitset<x>;
        Set dp;
        Set res;
        dp.set(0);
        for(int a : A){
            Set nx = dp;
            nx <<= a;
            res |= nx & dp;
            dp |= nx;
        }
        for(int i=0; i<x; i++) if(res.test(i)){ ans = Z - i * 2; break; }
    });
    if(ans <= 0) ans = -1;
    cout << ans << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0