結果

問題 No.1594 Three Classes
ユーザー rianoriano
提出日時 2021-07-09 21:37:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 167,112 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 00:04:06
合計ジャッジ時間 2,367 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 36 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 36 ms
6,940 KB
testcase_06 AC 34 ms
6,940 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 36 ms
6,944 KB
testcase_09 AC 38 ms
6,940 KB
testcase_10 AC 34 ms
6,940 KB
testcase_11 AC 34 ms
6,940 KB
testcase_12 AC 35 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 35 ms
6,940 KB
testcase_15 AC 34 ms
6,944 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 33 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 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