結果
問題 | No.2840 RGB Plates |
ユーザー | karinohito |
提出日時 | 2024-08-09 22:43:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 600 bytes |
コンパイル時間 | 4,594 ms |
コンパイル使用メモリ | 265,968 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-18 00:57:11 |
合計ジャッジ時間 | 5,619 ms |
ジャッジサーバーID (参考情報) |
judge2 / 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; }