結果
問題 | No.2840 RGB Plates |
ユーザー |
|
提出日時 | 2024-08-09 22:43:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 600 bytes |
コンパイル時間 | 4,237 ms |
コンパイル使用メモリ | 255,408 KB |
最終ジャッジ日時 | 2025-02-23 21:54:56 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include<atcoder/all> using namespace atcoder; using ll = long long; const ll mod=998244353; using BS=bitset<130010>; int main() { ll N; cin>>N; vector<ll> A(N); for(ll &a:A)cin>>a; sort(A.begin(),A.end()); BS B; B[0]=1; ll an=1e18; ll S=0; for(int i=0;i<N;i++){ S+=A[i]; BS NB=B; NB<<=A[i]; // cout<<NB<<endl; BS P=NB&B; if(P.any()){ an=min(an,ll(P._Find_first())); } B=NB|B; } cout<<(an<1e18&&S-2*an>0?S-2*an:-1)<<endl; }