結果

問題 No.1594 Three Classes
ユーザー KnotsKnots
提出日時 2021-07-19 23:45:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 204,436 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 00:41:59
合計ジャッジ時間 2,374 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = (1<<30)-1;
const int MOD = 1e9+7;
const ll LINF = (1ll<<62)-1;

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";

int main(){
    //input
    int n;cin >> n;
    vector<int> e(n);
    int num = 0;
    REP(i,n){
        cin >> e[i];
        num += e[i];
    }
    if(num%3!=0){
        COUT("No");
        return 0;
    }
    //bit-search
    vector<int> vec1;
    for(int bit=0;bit<(1<<n);bit++){
        int num1 = 0;
        vec1.clear();
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                num1 += e[i];
            }
            else vec1.push_back(e[i]);
        }
        if(num1==num/3)break;
    }
    bool flag = 0;
    for(int bit=0;bit<(1<<vec1.size());bit++){
        int num1 = 0;
        for(int i=0;i<vec1.size();i++){
            if(bit&(1<<i)){
                num1 += vec1[i];
            }
        }
        if(num1==num/3){
            flag = 1;
            break;
        }
    }
    if(flag)COUT("Yes");
    else COUT("No");
}
0