結果
問題 | No.2840 RGB Plates |
ユーザー |
|
提出日時 | 2024-08-09 23:09:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,764 ms / 2,000 ms |
コード長 | 2,563 bytes |
コンパイル時間 | 8,332 ms |
コンパイル使用メモリ | 350,220 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-08-18 01:00:46 |
合計ジャッジ時間 | 34,965 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#pragma GCC target("avx2")#pragma GCC optimize("O3")#pragma GCC optimize("unroll-loops")#include <bits/stdc++.h>using namespace std;#include <atcoder/all>using namespace atcoder;using mint = modint998244353;using vm = vector<mint>;using vvm = vector<vm>;inline ostream &operator<<(ostream &os, const mint x){return os << x.val();};inline istream &operator>>(istream &is, mint &x){long long v;is >> v;x = v;return is;};struct Fast{Fast(){std::cin.tie(nullptr);ios::sync_with_stdio(false);cout << setprecision(10);}} fast;#define all(a) (a).begin(), (a).end()#define contains(a, x) ((a).find(x) != (a).end())#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--)#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";#define yn(b) cout << ((b) ? "yes" : "no") << "\n";template <class T>inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}template <class T>inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}using ll = long long;using vb = vector<bool>;using vvb = vector<vb>;using vi = vector<int>;using vvi = vector<vi>;using vl = vector<ll>;using vvl = vector<vl>;template <typename T1, typename T2>ostream &operator<<(ostream &os, pair<T1, T2> &p){os << "(" << p.first << "," << p.second << ")";return os;}template <typename T>ostream &operator<<(ostream &os, vector<T> &vec){for (int i = 0; i < (int)vec.size(); i++){os << vec[i] << (i + 1 == (int)vec.size() ? "" : " ");}return os;}template <typename T>istream &operator>>(istream &is, vector<T> &vec){for (int i = 0; i < (int)vec.size(); i++)is >> vec[i];return is;}ll floor(ll a, ll b) { return a >= 0 ? a / b : (a + 1) / b - 1; }ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }void solve(){int n;cin >> n;vi a(n);cin >> a;int m = 0;for (auto x : a)m += x;using bs = bitset<7500001>;bs bs1;bs1[0] = 1;int ans = -1;rep(i, 0, n){int k = (bs1 & (bs1 << a[i]))._Find_first();if (k > 0 && m - 2 * k > 0)ans = max(ans, m - 2 * k);bs1 |= bs1 << a[i];}cout << ans << "\n";}int main(){int t = 1;// cin >> t;while (t--)solve();}