結果

問題 No.1594 Three Classes
ユーザー rianoriano
提出日時 2021-07-09 21:37:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 165,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 06:45:45
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;

ll mod = 1000000007;

int main() {
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    rep(i,N){
        cin >> a[i];
        sum += a[i];
    }
    string ans = "No";
    if(sum%3!=0){
        cout << ans << endl; return 0;
    }
    sum /= 3;
    //bitsearch bit全探索  3か所ある20は仮のbit列長さ
    //3^N subset ver
    for(int tmp=0;tmp<(1<<20);tmp++){
        if(tmp>=(1<<N)){ //ここでループ回数を入力に合わせる
            break;
        }
        for(int bit=tmp; ;bit=((bit-1)&tmp)){
            //ここに処理を書く
            ll c= 0,b = 0;
            rep(i,N){
                if(bit&(1<<i)){
                    c += a[i]; 
                }
                else if(tmp&(1<<i)){
                    b += a[i];
                }
            }
            if(b==sum&&c==sum) ans = "Yes";
            if(!bit) break;
        }
    }
    cout << ans << endl;
}
0