結果

問題 No.2840 RGB Plates
ユーザー chineristACchineristAC
提出日時 2024-08-09 21:29:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,705 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 163,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-18 00:55:27
合計ジャッジ時間 2,800 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 5 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 22 ms
5,376 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 22 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 17 ms
5,376 KB
testcase_18 AC 22 ms
5,376 KB
testcase_19 AC 22 ms
5,376 KB
testcase_20 AC 22 ms
5,376 KB
testcase_21 AC 21 ms
5,376 KB
testcase_22 AC 21 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 14 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 11 ms
5,376 KB
testcase_29 AC 14 ms
5,376 KB
testcase_30 AC 21 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <chrono>





using namespace std;









#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << " )\n";

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<endl;
}



template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& A){
  os << "(" << A.first <<", " << A.second << ")";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const set<T>& S){
  os << "set{";
  for (auto a:S){
    os << a;
    auto it = S.find(a);
    it++;
    if (it!=S.end()){
      os << ", ";
    }
  }
  os << "}";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const tuple<T,T,T>& a){
  auto [x,y,z] = a;
  os << "(" << x << ", " << y << ", " << z << ")";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const map<ll,T>& A){
  os << "map{";
  for (auto e:A){
    os << e.first;
    os << ":";
    os << e.second;
    os << ", ";
  }
  os << "}";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
  os << "[";
  rep(i,A.size()){
    os << A[i];
    if (i!=A.size()-1){
      os << ", ";
    }
  }
  os << "]" ;
  return os;
}


void solve(){
  int N;
  cin>>N;
  
  bitset<100000> dp;
  dp[0] = 1;
  int mini = 1e9;
  int S = 0;
  for (int i=0;i<N;i++){
    int a; cin>>a;
    S += a;
    
    bitset<100000> ndp = dp<<a;
    if ((ndp & dp).any()){
      int check = (ndp & dp)._Find_first();
      chmin(mini,check);
    }
    dp |= ndp;
  }

  if (mini == 1e9 || S == 2 * mini){
    cout << -1 << endl;
  }
  else{
    cout << S - 2 * mini << endl;
  }





  



}




int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);


  int T;
  T = 1;
  while (T--){
    solve();
  }
    
}
0